Cocos2dx 显示当前日期时间

前端之家收集整理的这篇文章主要介绍了Cocos2dx 显示当前日期时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 获取当前的时间,windowsandroid都适用 <span id="articlecontent"></span><pre>struct tm *tm;
  2. time_t timep;
  3. time(&timep);
  4. tm = localtime(&timep);
  5. int year = tm->tm_year + 1900;
  6. int month = tm->tm_mon + 1;
  7. int day = tm->tm_mday;
  8. int hour=tm->tm_hour;
  9. int minute=tm->tm_min;
  10. int second=tm->tm_sec;
  11.  
  12. auto time_str = String::CreateWithFormat("%d / %d / %d,%d : %d : %d",year,month,day,hour,minute,second);
  13.  
  14. m_timeLabel = Label::createWithTTF(time_str->getCString(),"fonts/Marker Felt.ttf",24);
  15.  
  16. this->addchild(m_timeLabel,1);
  17.  
  18. schedule(schedule_selector(HelloWorld::UpdateTime),5);
  19.  
  20. void HelloWorld::UpdateTime(float dt)
  21. { <pre name="code" class="cpp"><pre> struct tm *tm;
  22. time_t timep;
  23. time(&timep);
  24. tm = localtime(&timep);
  25. int year = tm->tm_year + 1900;
  26. int month = tm->tm_mon + 1;
  27. int day = tm->tm_mday;
  28. int hour=tm->tm_hour;
  29. int minute=tm->tm_min;
  30. int second=tm->tm_sec;
  31.  
  32. auto time_str = String::CreateWithFormat("%d / %d / %d,second);
m_timeLabel->setString(time_str->getCString()); }

猜你在找的Cocos2d-x相关文章