cocos2d-x3.x 获取系统时间

void getLocationTime()
{
    struct tm *tm;
    time_t timep;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    time(&timep);
#else
    struct timeval tv;
    gettimeofday(&tv,NULL);
    timep = tv.tv_sec;
#endif
    
    tm = localtime(&timep);
    int year = tm->tm_year + 1900;
    int month = tm->tm_mon + 1;
    int day = tm->tm_mday;
    int hour=tm->tm_hour;
    int minute=tm->tm_min;
    int second=tm->tm_sec;
    std::cout << "当前日期:" << year << "-" << month << "-" << day << std::endl;
    std::cout << "当前时间:" << hour << ":" << minute << ":" << second << std::endl;
}

 
 输出结果: 
 

当前日期:2014-7-13

当前时间:1:29:4

你可能感兴趣的:(C++,Class,iostream,cocos2d-x,cocos2d-x3.x)