码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx 3.x(获取当前系统时间)

时间:2016-10-21 07:59:18      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

 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(获取当前系统时间)

标签:

原文地址:http://www.cnblogs.com/luorende/p/5983238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!