获取的时间不对

来源:4-4 时钟程序-时钟逻辑(中)

qq_蜗牛_67

2016-06-01 14:41


struct timeval nowTimeval;

gettimeofday(&nowTimeval,NULL);

struct tm *tm;

time_t time_sec;

time_sec = nowTimeval.tv_sec;

tm = localtime(&time_sec);


CCLOG("hour = %d ,minitue = %d, second = %d",tm->tm_hour,tm->tm_min,tm->tm_sec);


写回答 关注

1回答

  • qq_蜗牛_67
    2016-06-01 16:22:16
    	win32 平台,获取时间
    	
    	struct tm *tm;
    	time_t timep;
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    	time(&timep);
    #else
    	struct cc_timeval now;
    	CCTime::gettimeofdayCocos2d(&now, NULL);
    	timep = now.tv_sec;
    #endif
    
    
    	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 min = tm->tm_min;
    	int second = tm->tm_sec;


Cocos2d-x基础教程二-会动的时钟

本课程为Cocos2d-x入门教程第二门,是对基础元素的讲解

19036 学习 · 44 问题

查看课程

相似问题