前端之家收集整理的这篇文章主要介绍了
Cocos2dx 显示当前日期时间,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- 获取当前的时间,windows和android都适用 <span id="articlecontent"></span><pre>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;
-
- auto time_str = String::CreateWithFormat("%d / %d / %d,%d : %d : %d",year,month,day,hour,minute,second);
-
- m_timeLabel = Label::createWithTTF(time_str->getCString(),"fonts/Marker Felt.ttf",24);
-
- this->addchild(m_timeLabel,1);
-
- schedule(schedule_selector(HelloWorld::UpdateTime),5);
-
- void HelloWorld::UpdateTime(float dt)
- { <pre name="code" class="cpp"><pre> 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;
-
- auto time_str = String::CreateWithFormat("%d / %d / %d,second);
m_timeLabel->setString(time_str->getCString()); }