首页 > 代码库 > cocos2dx 3.x(获取当前系统时间)
cocos2dx 3.x(获取当前系统时间)
1 // 2 // MainScene.cpp 3 // helloworld 4 // 5 // Created by apple on 16/10/21. 6 // 7 // 8 9 #include "MainScene.hpp" 10 USING_NS_CC; 11 Scene * MainScene::createScene() 12 { 13 auto scene = Scene::create(); 14 // CCScene * scene = CCScene::create();// 创建场景 15 //创建层 16 MainScene *layer = MainScene::create(); 17 scene->addChild(layer); 18 return scene; 19 } 20 bool MainScene::init(){ 21 if (!Layer::init()) { 22 return false; 23 } 24 //获取屏幕大小 25 size = Director::getInstance()->getVisibleSize(); 26 //auto size = Director::getInstance()->getWinSize(); 27 28 //获取系统时间 29 struct timeval now; 30 struct tm *time; 31 32 gettimeofday(&now, NULL); 33 34 time = localtime(&now.tv_sec); //microseconds: 微秒 35 int year = time->tm_year +1900; 36 log("year = %d", year); //显示年份 37 38 char date1[32] = {0}; 39 sprintf(date1, "%d %02d %02d", (int)time->tm_year + 1900, (int)time->tm_mon + 1, (int)time->tm_mday); 40 log("%s", date1); //显示年月日 41 42 char date2[50] = {0}; 43 sprintf(date2, "%02d %02d %02d", (int)time->tm_hour, (int)time->tm_min, (int)time->tm_sec); 44 log("%s", date2); //显示时分秒 45 46 //return StringUtils::format("%s", date); std::string getcurrTime(){} 47 48 return true; 49 }
cocos2dx 3.x(获取当前系统时间)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。