Python embedded Module--time

Source: Internet
Author: User

in fact, in Python, time is simply the following two forms of existence:
Time, there are generally two kinds of temporal forms:
1. Timestamp: Offset calculated in seconds relative to 1970.1.1 00:00:00
2. Tuple form: Struct_time

The methods of the time module are:
Time.clock ():
The first call returns a CPU time unit that is called from the program to create the program process to the clock () function call
The second call, which returns the time interval from the first call to this call

time.sleep ():Thread delays the specified time run

time.ctime ():Tell a timestamp (the default is the current time) and convert it into a time string
Such as:
Print Time.ctime (); = Mon Oct 20 14:40:38 2014 default current time

time.gmtime ():Converts a timestamp into a UTC time zone Struct_time, which defaults to the current time
Such as:
Print Time.gmtime (); = = Time.struct_time (tm_year=2014, tm_mon=10, tm_mday=20, tm_hour=6, tm_min=43, tm_sec=38, tm_wday=0, tm_yday=293, TM _isdst=0)

time.localtime ():Converts a timestamp into a struct_time of the current time zone, with the default
Such as:
Print time.localtime () = Time.struct_time (tm_year=2014, tm_mon=10, tm_mday=20, tm_hour=14, tm_min=48, TM_SEC=44, TM _wday=0, tm_yday=293, tm_isdst=0)

time.mktime ():Convert a struct_time to a timestamp, the parameter must be a struct_time tuple form (year, month, day, hour, minute, second, Tm_wday: The day of the week, 0~6,tm_yday: The day of the year, TM_ISDST: Xia Lingzhi)
Such as:
Print Time.mktime ((2014,10,20,14,48,44,0,293,0)) = 1413787724.0

time.strftime ():Outputs the specified Struct_time (default current time), based on the specified formatted string
time-date formatting symbols in Python:
%y Two-digit year (00-99)
%Y Four-digit year (000-9999)
%m Month (01-12)
One day in%d months (0-31)
%H 24-hour system hours (0-23)
%l 12-hour system hours (01-12)
%M minutes (00-59)
%s seconds (00-59)

Strftime (Format[,tuple])->string
Such as:
Print Time.strftime ("%y,%m,%d", (2013,06,16,12,50,36,5,6,1)) =>13,06,16 returns a string

strptime ():Converts a time string to an array of time based on a specified format character
Strptime (String,format)->struct_time
Such as:
Print time.strptime (' 2014,03,02 ', '%y,%m,%d ')
Time.struct_time (tm_year=2014, tm_mon=3, tm_mday=2, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=61, Tm_isdst=-1)

time.time (): Returns the current timestamp

Python embedded Module--time

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: 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.