Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a preferred way to get the system time in cocos2d-x?

I am writing a cross-platform application in Cocos2d-x. I need to get the time to create a countdown clock to a certain time of day. Since it is in C++, I can use time(...), mktime(...), and difftime(...) if I need to as a direct approach.

Is there a preferred method in Cocos2d-x for doing this in a cross-platform way (i.e. something built directly into the framework)? I want the app to work the same on iPhones, iPads, and Android.

like image 518
FuzzyBunnySlippers Avatar asked Dec 11 '25 09:12

FuzzyBunnySlippers


1 Answers

try this:

time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);

CCLog("year------->%04d",timeinfo->tm_year+1900);
CCLog("month------->%02d",timeinfo->tm_mon+1);
CCLog("day------->%02d",timeinfo->tm_mday);

CCLog("hour------->%02d",timeinfo->tm_hour);
CCLog("minutes------->%02d",timeinfo->tm_min);
CCLog("seconds------->%02d",timeinfo->tm_sec);
like image 96
KARTHIK RA Avatar answered Dec 14 '25 06:12

KARTHIK RA