Time (null) Usage

Source: Internet
Author: User
Tags time in milliseconds

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

 
 
  1. Long Millisecondnow ()
  2. {
  3. Struct Cc_timeval now;
  4. cctime: gettimeofdaycocos2d (& now, null);
  5. Return (Now. TV _sec * 1000 + now. TV _usec/1000 );
  6. }

The next step is to record the time of each operation, and then determine the time difference to perform the desired operation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.