time(null)的用法

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获取时间到毫秒

 
 
  1. long millisecondNow()  
  2. struct cc_timeval now; 
  3. CCTime::gettimeofdayCocos2d(&now, NULL); 
  4. return (now.tv_sec * 1000 + now.tv_usec / 1000); 

接下来就是记录每次的时间,然后判断时间差,就可以进行想要的操作了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值