How to get current date,time,month and year in cocos2dx | Techbirds
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;
3,735 total views, 1 views today
Share this On Tags: android, C++, cocos2dx, Game-development, ios