Linux time management functions

Source: Internet
Author: User
Tags month name time zone names


Linux Time management functions in LInux, the difference between UTC Time and Local Time must be clarified for Time management. 1) UTC: GMT (Greenwich Mean Time) 2) local Time is the default time zone configuration file of the Local Time system. The location of the file is/etc/sysconfig/clock. During programming, you often need to read time, process running Time, and other information at time. the h header file declares that these functions www.2cto.com clock () are used to view the running time of the process, and the declaration is as follows: extern clock_t clock (void). This function returns the running time of the current time, the result is the clock Counter value and is converted to the second formula: result/CLODKS_PER_SECOND function time () is used to obtain the current system time. The function declaration is as follows: extern time_t time (time_t * _ timer) The time is from Number of seconds. If the parameter is blank, the return time is in seconds. If the parameter is not blank, it is stored in the modified parameter. Converts the number of seconds to the time format. extern char * ctime (_ const time_t * _ timer) returns the current time string extern struct tm * gmtime (_ const time_t * _ timer) and returns the current time, the time reference is UCT extern struct tm * localtime (_ const time_t * _ timer) and returns the local time. The time reference is the currently set time zone tm structure to obtain the date and time, the tm structure is in time. the definition in h is as follows: # ifndef _ TM_DEFINED struct tm {www.2cto.com int tm_sec;/* Second-value range: [] */int tm_min; /* minute-value range: [] */int tm_hour;/* hour-value range: [] */int tm_mday;/* month The date-value range is [] */int tm_mon;/* month (starting from January 1, 0 indicates January 1,)-value range is [] */int tm_year; /* year, with a value starting from 1900 */int tm_wday;/* week-value range: [0, 6], where 0 indicates Sunday, 1 indicates Monday, and so on */int tm_yday; /* The number of days starting from January 1, 0,365-the value range is []. 0 indicates January 1, and so on. */int tm_isdst;/* indicates the identifier of the hour, when the sequence is executed, tm_isdst is positive. When the sequence is not implemented, the tm_isdst value is 0. If the sequence is unknown, the tm_isdst () value is negative. */Long int tm_gmtoff;/* specifies the positive seconds of the UTC Eastern Time Zone in the Eastern Time Zone of the date change line or the negative seconds of the UTC western time zone */const char * tm_zone; /* Name of the current time zone (associated with the environment variable TZ) */}; www.2cto.com if you need to convert the time type into a time string that people are used, call the asctime function extern char * asctime (_ const struct tm * _ tp) to extract an item from struct tm, call the strftime () function to format the time, or: format a time string. Header file: time. h function prototype: We can use the strftime () function to format the time to the desired format. Its prototype is as follows: size_t strftime (char * strDest, size_t maxsize, const char * format, const struct tm * timeptr); parameter description of www.2cto.com: you can place the time information stored in timeptr in the strDest string based on the format command in the string to which the strDest points. A maximum of maxsize characters can be stored in strDest. This function returns the number of characters placed in the string pointing to strDest. The strftime () function is similar to sprintf (): recognizes the command set starting with the percent sign (%), and formats the output result in a string. The formatting command specifies the exact representation of various date and time information in strDest. Other characters in the format string are put into the string as they are. Format Commands are listed below, which are case sensitive. % A abbreviation of the day of the week % A the full name of the day of the week % B the abbreviation of the month % B the full name of the % c standard date time string % C the last two digits of the Year % d decimal the day % D month/day/year % e of the month is in the two-character domain, the last two digits of the day % F-month-day % g Year of the month in decimal format, which are based on the year % G Year of the week, the day of each year % m decimal month in the hour % I 12 hour format of the month name % h 24 hour format % M in decimal format: www.2cto.com % n newline operator % p local AM or PM equivalent display % r 12 hour time % R display hour and minute: hh: mm % S decimal seconds % t horizontal tab % T display hour minute Second: hh: mm: ss % u day of the week, Monday is the first day (value from 0 to 6, monday is 0) % U the week of the year, and Sunday is used as the day of the first day (value ranges from 0 to 53) % V the week of the year, The day of the week (ranging from 0 to 6, with Sunday 0) % w indicates the week of the year, use Monday as the first day (value ranges from 0 to 53) % x standard date string www.2cto.com % X standard time string % y without century decimal year (value ranges from 0 to 99) % Y indicates the tenth year % z and % Z Time Zone names of century. If the time zone name cannot be obtained, an empty character is returned. % Percent sign
 

Related Article

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.