在CCTime中,存在接口gettimeofdayCocos2d:
class CC_DLL CCTime { public: static int gettimeofdayCocos2d(struct cc_timeval *tp,void *tzp); static double timersubCocos2d(struct cc_timeval *start,struct cc_timeval *end); };
我们调用接口获取时间,但是这个时间只有秒和微妙,就需要我们自己进行装换了:
int getCurrentTime() { struct cc_timeval Now; CCTime::gettimeofdayCocos2d(&Now,NULL); return Now.tv_sec * 1000 + Now.tv_usec / 1000; }