cocos2dx 3.1获取系统当前时间

cocos2dx 3.1获取系统当前时间,第1张

概述std::string Tools::getcurrTime(){ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) struct timeval now; struct tm* time; gettimeofday(&now, NU
std::string Tools::getcurrTime(){     #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);  int year = time->tm_year + 1900;  log("year = %d",year);    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);  return StringUtils::format("%s",date);    #endif    #if ( 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",date);   return StringUtils::format("%s",date);    #endif  }

以上是获取当前年月日

---------------------------------详解的其他方法

linux,ios下的

struct cc_timeval Now;   CCTime::gettimeofdayCocos2d(&Now,NulL);   struct tm *tm;  tm = localtime(&Now.tv_sec);  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;  long millSecond=Now.tv_sec * 1000 + Now.tv_usec / 1000;
win32下:
struct tm *tm;  time_t timep;  time(&timep);  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;
总结

以上是内存溢出为你收集整理的cocos2dx 3.1获取系统当前时间全部内容,希望文章能够帮你解决cocos2dx 3.1获取系统当前时间所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1061689.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存