有没有一种在cocos2d-x中获取系统时间的首选方法?

Fuz*_*ers 3 android cocos2d-x cocos2d-x-3.0

我正在用Cocos2d-x编写一个跨平台的应用程序.我需要花时间在一天的特定时间创建一个倒计时钟.因为它是在C++中,所以如果我需要作为直接方法,我可以使用时间(...),mktime(...)和difftime(...).

在Cocos2d-x中是否有一种首选方法可以跨平台方式(即直接构建到框架中)?我希望该应用程序在iPhone,iPad和Android上的工作方式相同.

小智 5

试试这个:

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);
Run Code Online (Sandbox Code Playgroud)