Python Module-time module

Source: Internet
Author: User

Time.time (): Returns the timestamp of the current time

>>> time.time () 1518789643.737527

Time.localtime ([secs]): Converts a timestamp to the struct_time of the current time zone. secs parameter if not provided, whichever is the current time

>>> time.time () 1518790500.354652>>> time.localtime () time.struct_time (tm_year=2018, tm_mon=2, tm_ Mday=16, tm_hour=22, tm_min=15, tm_sec=3, tm_wday=4, tm_yday=47, tm_isdst=0) >>> Time.localtime ( 1518790500.354652) Time.struct_time (tm_year=2018, tm_mon=2, tm_mday=16, tm_hour=22, tm_min=15, tm_sec=0, Tm_wday=4, TM _yday=47, tm_isdst=0)

Time.gmtime ([secs]): Similar to the LocalTime () method, the Gmtime () method is to convert a timestamp to a struct_time of UTC time Zone (0 o'clock Zone), eight hours later than China

>>> Time.gmtime (Time.struct_time) (tm_year=2018, tm_mon=2, tm_mday=16, tm_hour=14, tm_min=16, tm_sec=49, tm_ Wday=4, tm_yday=47, tm_isdst=0) >>> time.gmtime (1518790500.354652) time.struct_time (tm_year=2018, tm_mon=2, Tm_mday=16, tm_hour=14, tm_min=15, tm_sec=0, tm_wday=4, tm_yday=47, tm_isdst=0)

Time.mktime (t): Converts a struct_time to a timestamp

>>> Time.mktime (Time.localtime ()) 1518790773.0>>> Time.mktime (Time.localtime ()) 1518790779.0

Time.sleep (secs): Thread delays a specified time to run, that is, sleep, in seconds

>>> Time.sleep (3)  #睡眠3秒

Time.asctime ([t]): A tuple or struct_time representing time is represented in this form: Fri Feb 16 22:54:04 2018. If there are no parameters, the Time.localtime () will be passed in as a parameter

>>> time.asctime () ' Fri Feb 16 22:56:13 2018 '

Time.ctime ([secs]): Converts a timestamp (floating point number in seconds) to the form of Time.asctime (). If the parameter is not given or is none, the default Time.time () is the parameter. Its role is equivalent to Time.asctime (time.localtime (secs))

>>> time.time () 1518793099.0701997>>> time.ctime () ' Fri Feb 22:58:33 2018 ' >>> time.ctime ( 1518793099.0701997) ' Fri Feb 16 22:58:19 2018 '

Time.strftime (format[, T]): Converts a tuple or struct_time representing time into a formatted time string. If T is not specified, the Time.localtime () is passed in

>>> time.strftime ('%y-%m-%d%h:%m:%s ') ' 2018-02-16 23:26:38 ' >>> time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime ()) ' 2018-02-16 23:26:52 ' >>> time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime ( 1518793099.0701997)) ' 2018-02-16 22:58:19 '

Time.strptime (string[, format]): Converts a formatted time string to Struct_time, and strftime () is an inverse operation

>>> time.strptime (' 2018-2-16 23:28:43 ', "%y-%m-%d%h:%m:%s") time.struct_time (tm_year=2018, tm_mon=2, tm_ Mday=16, tm_hour=23, tm_min=28, tm_sec=43, tm_wday=4, tm_yday=47, Tm_isdst=-1)
String to time format corresponding table
%a English abbreviations for the week
%A English full name of week
%b Abbreviation of month English name
%B Month English full name
%c Current date and time, formatted as ' Fri Feb 16 23:42:21 2018 '
%d Month Date [01,31]
%H Hours [00,23]
%I Hours (12-hour) [01,12]
%j Day of the year [001,366]
%m month [1,12]
%M minutes [0,59]
%p Morning and afternoon [AM,PM]
%s seconds [00,61]
%u The number of weeks in a year (Sunday as the first day of the week) as a decimal number [00,53], the first Sunday of the year before all days are considered to be in the No. 0 week
%w Week, results for numbers [0 (Sunday), 6]
%W The number of weeks in a year (Monday as the first day of the week) as a decimal number [00,53], the first Monday before a new year all day is considered to be in the No. 0 week
%x Current date, formatted as ' 02/16/18 '
%x Current time
%y The time difference between the current and UTC time
%Y Year
%z The time difference between the current and UTC time
%Z The name of your time zone

Python Module-time module

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.