安卓和iOS上获取系统时间:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
struct timeval now;
struct tm* time;
gettimeofday(&now, NULL);
time = localtime(&now.tv_sec);
char date[32] = {0};
sprintf(date, "%02d:%02d",(int)time->tm_hour ,(int)time->tm_min);
auto str = StringUtils::format("%s",date);
timeLab->setString(str.c_str());
#endif
win32上面获取系统时间:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 )
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%H:%M",localtime(&t) );
timeLab->setString( tmp );
#endif
Lua语言获取系统时间:
os.date( format,time ) -- 第一个参数以什么格式返回,第二个参数为时间戳
local timeDate = os.date("%y.%m.%d", dateTime ) -- 年月日格式返回(16.09.07)
local d = os.date("%m-%d %H:%M", dateTime ) -- 返回格式: "04-21 19:00"