c&c++ datetime

Source: Internet
Author: User
Tags local time month name string format

The relationship between time functions

struct tm{    int tm_sec;    Represents the current number of seconds, normal range 0-59, but allowed to 61 seconds;    int tm_min;    Represents the current score with a range of 0-59.    int tm_hour;   The number of hours from midnight, in the range of 0-23.    int tm_mday;   The number of days in the current month, the range is 1-31.    int Tm_mon;    Represents the current month, starting from January, with a range of 0-11.    int tm_year;   The number of years since 1900. For example (timestamp 1970-01-02 10:23:09, this value is 70).    int tm_wday;   The number of days in a week, from Sunday onwards, ranges from 0-6.    int tm_yday;   The number of days since January 1, ranging from: 0-365.    int tm_isdst;  The flag of daylight saving time. };
  #include <time.h>time_t time (time_t * t);  This function returns the number of seconds from 0:0 to 0 seconds since the UTC time in A.D. January 1, 1970. If T is not a null pointer, this function also saves the return value to the memory referred to by the T-pointer. If it fails, it returns ((time_t)-1).  #include <time.h>struct TM * gmtime (const time_t * TIMEP);  The function converts the information in the time_t structure referred to by the parameter TIMEP to the date representation method used by the real world, and then returns the result from the Fabric TM. The return value represents the current UTC time.  #include <time.h>struct TM * localtime (const time_t * TIMEP);  The function converts the information in the time_t structure referred to by the parameter TIMEP to the date representation method used by the real world, and then returns the result from the Fabric TM. The return value represents the local time of the current local time zone.  #include <time.h>time_t mktime (struct TM * timeptr);  This function converts the TM structure data referred to by the parameter timeptr to the number of seconds elapsed since the UTC time of January 1, 1970 0:0 0 seconds.  #include <time.h>size_t strftime (char *s, size_t max, const char *format, const struct TM *tm);  The function converts the parameter tm into a string format specified by the parameter format, and the converted string is copied to the string array referred to in parameter s, the maximum length of which is controlled by the parameter max.  #include <time.h>char *strptime (const char *s, const char *format, struct TM *tm);  The function converts the string specified by the parameter S to a certain format requirement, which is converted to the value of the TM structure according to the format parameter formats. If parsing error, returns NULL. 
Format parameters for strftime and Strptime
Parameters Meaning
%a Shorthand for the day of the week
%A Full name of the day of the week
%A Full name of the day of the week
%b Shorthand for the month
%B Full name of the month
%c Time string of the standard date
%c The first two digits of the year, such as 1997, are: 19
%d The day ordinal of a month, expressed in decimal notation: 01-31
%d The format is "month/day/year" to indicate the time. Equivalent to the "%m%d%y" format. For example "19970701"
%e The day ordinal of a month in decimal notation (not 0), the notation is: 1-31.
%F Use the "%y-%m-%d" format to represent the date. For example "1997-07-01".
%g The following two digits of the year, such as 1997, are: 97
%G The full year of A.D., for example, 1997 indicates: 1997
%h As with "%b", the abbreviated month name.
%H The number of hours (00-23) is expressed in a 24-hour system.
%I The number of hours (01-12) is expressed in a 12-hour system.
%j Decimal indicates the number of days in a year (001-366).
%k With "%H", the notation is: 0-23
%l With "%I", the notation is: 1-12.
%m The decimal representation of the month, notation: 01-12.
%M The number of minutes represented by the 10 o'clock notation: 00-59.
%n Same as "\ n", newline.
%p Equivalent display of local AM or PM.
%P Similar to "%p", but denoted by lowercase am and PM.
%r Equivalent to using the "%i:%m:%s%p" format, for example: "08:31:50 PM".
%R Equivalent to using the "%h:%m" format, for example: "22:31".
%s The number of seconds in decimal, notation: 00-59.
%t Horizontal tab, same as "\ T"
%T 24 hours is the equivalent of the "%h:%m:%s" format.
%u Sunday period of the week, Range: 1-7, Monday starting from 1.
%u Number of weeks in the year, Range: 00-53, January the first Sunday starts at 01.
%V Number of weeks in the year, Range: 00-53, January the first Monday starts at 01.
%w Sunday period of the week, Range: 0-6, Sunday starting from 0.
%W Number of weeks in the year, Range: 00-53, January the first Monday starts at 01.
%x A standard date string. such as January 2, 2017, said: "01/02/17".
%x A standard time string. For example, January 2, 2017 10:23 9 seconds, expressed as: "10:23:09".
%y Decimal year without century (values from 0 to 99)
%Y 10 year with century part
%z,%z The time zone name that returns a null character if the time zone name cannot be obtained.
%% Percent Sign
about%u parameters:
For example, the January 1 of 2017 is Sunday, and the value obtained with%u is "01"
For example, the January 1 of 2016 is Friday, and the value obtained with%u is "00"

about the%v parameter:
For example, 2017 of January 1 is Sunday, using%v to get the value is "52"
For example, 2017 of January 1 is Monday, using%v to get the value is "01"
For example, 2016 of January 1 is Friday, using%v to get the value is "53"
Update record 1.20170720 update time function diagram;

c&c++ datetime

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.