Time_t time1 = Time (null); // obtain the system time, in seconds;
TM * time = localtime (& time1); // convert to a struct of the TM type;
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 */
};
// Obtain the system time in milliseconds;
Related functions: time, ctime, gettimeofday
Header file: # include <sys/timeb. h>
Function Syntax: int ftime (struct timeb * TP );
Function Description: ftime () returns the current date from the structure indicated by TP. TP structure definition:
Struct timeb {
Time_t time;/* indicates the number of seconds since January 1 */
Unsigned short millitm;/* 1‰ seconds, that is, milliseconds */
Short timezonel;/* indicates the time difference between the current time zone and Greenwich. The unit is minute */
Short dstflag;/* indicates the corrected state of daylight saving time. If it is not 0, the daylight saving time correction is enabled */
};
// Cocos2d-x acquisition time to milliseconds
- Long Millisecondnow ()
- {
- Struct Cc_timeval now;
- cctime: gettimeofdaycocos2d (& now, null);
- Return (Now. TV _sec * 1000 + now. TV _usec/1000 );
- }
The next step is to record the time of each operation, and then determine the time difference to perform the desired operation.