c The time library function time() gmtime() mktime() localtime()

1. Data structure

      time_t integer; 64-bit integer under linux, 64-bit integer under windows, you can open the macro _USE_32BIT_TIME_T to force interpretation as 32-bit integer.

      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 */

        };//Note that tm_mon tm_year tm_wday tm_yday is not from the beginning, pay attention to processing

2. Conversion

      time => time_t (UTC)

      gmtime; time_t(UTC)=>tm The upper limit of time is 2038 or 3000 (depending on time_t 32-bit or 64-bit)

      mktime; tm(calendar)=>time_t

      _mkgmtime; tm(UTC)=>time_t

      localtime;time_t(UTC)=>tm(calendar)

//These functions are not thread-safe, due to shared tm, coverage problems may occur

reference:

https://docs.microsoft.com/zh-cn/previous-versions/1f4c8f33(v=vs.110)?redirectedfrom=MSDN

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa272948%28v%3dvs.60%29

https://docs.microsoft.com/zh-cn/previous-versions/w4ddyt9h%28v%3dvs.120%29

Guess you like

Origin blog.csdn.net/beebeeyoung/article/details/103174535