安卓和iOS上獲取系統(tǒng)時(shí)間:
#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上面獲取系統(tǒng)時(shí)間:
#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語(yǔ)言獲取系統(tǒng)時(shí)間:
os.date( format,time ) -- 第一個(gè)參數(shù)以什么格式返回庄拇,第二個(gè)參數(shù)為時(shí)間戳
local timeDate = os.date("%y.%m.%d", dateTime )? -- 年月日格式返回(16.09.07)
local d = os.date("%m-%d %H:%M",? dateTime )? -- 返回格式: "04-21 19:00"