time_t time1 = time(NULL);//获取系统时间,单位为秒;
tm * time = localtime(&time1);//转换成tm类型的结构体;
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
//获取系统时间到毫秒;
相关函数:time, ctime, gettimeofday
表头文件:#include <sys/timeb.h>
函数定义:int ftime(struct timeb *tp);
函数说明:ftime()将目前日期由tp所指的结构返回。tp结构定义:
struct timeb{
time_t time; /* 为1970-01-01至今的秒数*/
unsigned short millitm; /* 千分之一秒即毫秒 */
short timezonel; /* 为目前时区和Greenwich相差的时间,单位为分钟 */
short dstflag; /* 为日光节约时间的修正状态,如果为非0代表启用日光节约时间修正 */
};
//cocos2d-x获取时间到毫秒
- long millisecondNow()
- {
- struct cc_timeval now;
- CCTime::gettimeofdayCocos2d(&now, NULL);
- return (now.tv_sec * 1000 + now.tv_usec / 1000);
- }
接下来就是记录每次的时间,然后判断时间差,就可以进行想要的操作了。