目录

如何在cocos2dx中获取系统的年、月、日

目录

In order to get the current date,time,we can use 2 methods-either using the localtime of the desktop or using GMT(GREENWICH MEAN TIME)

//USING THE LOCAL TIME

time_t time;
struct tm * timeinfo;
time (&time);
timeinfo = localtime (&time);
CCLog("year->%d",timeinfo->tm_year+1900);
CCLog("month->%d",timeinfo->tm_mon+1);
CCLog("date->%d",timeinfo->tm_mday);
CCLog("hour->%d",timeinfo->tm_hour);
CCLog("minutes->%d",timeinfo->tm_min);
CCLog("seconds->%d",timeinfo->tm_sec);

 

//USIMG GMT Replace the above line

timeinfo = localtime (&time);withtimeinfo =gmtime (&time);

and since that gmtime is 5 hours 30 min. less than the India time,we have to add that much time to the gmtime time for the current india time

hour=tm_hour+5;
minutes=tm_min+30;
seconds=tm_sec;

原文:http://techbirds.in/how-to-get-current-datetimemonth-and-year-in-cocos2dx/