Detailed functions of the time module in Python

Source: Internet
Author: User
Tags julian day month name
>>> Import time >>> Dir (time) ['_ Doc _', '_ name _', '_ package __', 'accept2dyear ', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'Sleep ', 'strftime', 'strptime', 'struct _ time', 'time', 'timezone ', 'tzname']

After help (time), we can know that time has two time representation forms:
1. timestamp notation, that is, an integer or floating point represents a time interval in seconds. The base value of this time period starts from on January 1.
2. Format representation of tuples, that is, representation of a python data structure. This tuples have nine integer types. Different time meanings.

 
Year (four digits, e.g. 1998) month (1-12) Day (1-31) hours (0-23) minutes (0-59) seconds (0-59) weekday (0-6, monday is 0) Julian day (day in the year, 1-366) DST (daylight savings time) flag (-1, 0 or 1) # format of hour, 0: indicates the normal format, 1: indicates the time format,-1: indicates that it is determined based on the current date and time format.

Glossary:
UTC (Coordinated Universal Time) is the Greenwich Mean Time, the world standard time. UTC + 8 in China.
DST (Daylight Saving Time) is the daylight saving time. It is a system that artificially defines local time for saving energy. Generally, it is one hour ahead of time in the early summer.

Included variables:
Timezone-error between the local time and the standard UTC time, measured in seconds
Altzone-the error between the local clock time and the standard UTC time, measured in seconds
Daylight -- whether the local time reflects the cursor. The default value is 0.
Tzname -- tuples related to (Standard Time Zone name, Time Zone name at runtime)

Included functions:
Time () -- returns the current timestamp in the floating point format. Parameter not accepted
Clock () -- returns the currentProgramCPU execution time. The UNIX system always returns the full running time, while Windows uses the timestamp when this function is called for the first time as the benchmark from the second time, rather than the program start time as the benchmark. Parameters are not accepted.
Sleep ()-delay for a period of time, and accept integer and floating point types.
Gmtime () -- converts the timestamp to the UTC time tuples. Accept a floating point timestamp parameter. The default value is the current timestamp.
Localtime () -- convert the timestamp to the format of the local time tuples. Accept a floating point timestamp parameter. The default value is the current timestamp.
Asctime () -- convert the format of time tuples to the string format. Accepts a time tuples. The default value is the return value of localtime ().
Ctime () -- converts a timestamp to a string. Accept a timestamp. The default value is the current timestamp. Equivalent to asctime (localtime (seconds ))
Mktime () -- convert the local time tuples into timestamps. It is required to accept a time tuples.
Strftime () -- converts the time tuples into strings in the specified format. Format strings and time tuples. Time tuples are optional. The default value is localtime ()
Strptime () -- parses the time string in the specified format into a time tuple, which is the reverse process of strftime. String accepted. The time format is required.
Tzset () -- change the local time zone.

Supported time string format symbols:

 
Format description remarks % A local (locale) simplified week name % A local full week name % bsimplified month name % blocal full month name % clocal corresponding date and time represents the day of % d in a month (01- 31) % H the hour of the day (in 24-hour format, 00-23) % I the hour of the day (in 12-hour format, 01-12) % j day of the year (001-366) % m month (01-12) % m minutes (00-59) % P local am or PM operator % s second (01-61) % u the number of weeks in a year. (00-53 Sunday is the beginning of a week .) All days before the first Sunday are placed in week 0th. % W the day of a week (0-6, 0 is Sunday) % W and % u are basically the same, the difference is that % W starts from Monday as a week. % X local date % x local time % Y remove century year (00-99) % Y complete year % Z Time Zone name (if not null characters) % 'character

Note:
1. "% P" is effective only when used with "% I.
2. It is emphasized in the document that it is indeed 0-61, rather than 59. The leap second occupies two seconds (one perspiration ).
3. When the strptime () function is used, % u and % W are calculated only when the number of weeks and days in the year are determined.
 

A figure shows how to use the module:

Refer:

Http://qinxuye.me/article/details-about-time-module-in-python/

Http://docs.python.org/2/library/time.html

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.