cocos2dx 3.x(获取当前系统时间)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(获取当前系统时间)的主要内容,如果未能解决你的问题,请参考以下文章
cocos2dx 3.x(实现帧动画(人物动画,跑马灯效果)的几种方法)