time_t TM Timeval and time string conversions

Source: Internet
Author: User
Tags current time local time time interval
1, common time storage mode       1) time_t type, which is essentially a long integer representing the number of seconds from 1970-01-01 00:00:00 to the current time, if more precise is needed, You can use timeval precisely to milliseconds.       2) TM structure, which is essentially a struct that contains the time fields       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 */            };      where tm_year represents the number of years from 1900 to the current time interval, if the value is set manually, Tm_ ISDST usually takes a value of-1.       2, commonly used time functions       time_t time (time_t *t);  // Gets the number of seconds since January 1, 1970 &NBSP;&NBsp Char *asctime (CONST&NBSP;STRUCT&NBSP;TM&NBSP;*TM);  //converts information in a structure to real-world time, displayed as a string    char  *ctime (CONST&NBSP;TIME_T&NBSP;*TIMEP);  //convert TIMEP to True world time, as a string display, it differs from asctime in that the Parameter form passed in is different     Struct tm *gmtime (CONST&NBSP;TIME_T&NBSP;*TIMEP)  //converts the time represented by time_t to a UTC time that has no time zone conversion. is a STRUCT&NBSP;TM structure pointer     struct tm *localtime (CONST&NBSP;TIME_T&NBSP;*TIMEP);  // Similar to Gmtime, but it is time-zone-converted.    time_t mktime (STRUCT&NBSP;TM&NBSP;*TM)  //convert the time of struct tm  structure to the number of seconds from 1970 to present     Int gettimeofday (STRUCT&NBSP;TIMEVAL&NBSP;*TV,&NBSP;STRUCT&NBSP;TIMEZONE&NBSP;*TZ);  // Returns the number of seconds and subtleties of the current distance 1970, and the following TZ is the time zone, generally not    double difftime (time_t time1, time_t time2);  //returns two time difference in seconds          3, time and string conversion       the header file to include is as follows        #include  <iostream>   #include  <time.h>   #include <stdlib.h>   #include  <string.h>      1) unix/ Windows Time-to-string reference code       time_t t;  //sec time    tm* local; // local time  

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.