cocos2dx获取系统当前时间

#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, "%d/%02d/%02d %02d:%02d:%02d",
            (int)time->tm_year + 1900,
            (int)time->tm_mon + 1,
            (int)time->tm_mday,
            (int)time->tm_hour,
            (int)time->tm_min,
            (int)time->tm_sec);
    log("%s",date);
#elif ( CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 )
    struct tm* tm;
    time_t timep;
    time(timep);
    
    tm = localtime(&timep);
    char date[32] = {0};
    sprintf(date, "%d-%02d-%02d",(int)time->tm_year + 1900,(int)time->tm_mon + 1,(int)time->tm_mday);
    log("%s",date);
#endif

你可能感兴趣的:(Cocos2d学习笔记)