Python Basics-Day 5 learning note-Standard library of modules: Time (1)

Source: Internet
Author: User
Tags time zones month name

How time is expressed

1. inter-stamp timestamp: An offset calculated in seconds from January 1, 1970 00:00:00, rendered as a float data type. The functions that return timestamps are: Time (), clock (), and so on.

2. Sruct_time : Functions that return struct_time Ganso include Gmtime (), localtime (), Strptim (). The returned Ganso consists of the following 9 elements.

Indexed index Property ATTRIBUTE Value values
0 Tm_year Like 2011.
1 Tm_mon 1-12
2 Tm_mday 1-31
3 Tm_hour 0-23
4 Tm_min 0-59
5 Tm_sec 0-61
6 Tm_wday 0-6 (0 = Sunday)
7 Tm_yday (day ordinal of the year) 1-366
8 TM_ISDST (whether daylight saving time) Default #:-1

* Note-time zone: UTC (Coordinated Universal Time, world co-ordination). China utc+8. Dst:daylight Saving Time

3. formatted time string parsing and formattingtimes: The following format time string format expression

Format Meaning
%a Local Simplified Week name
%A Local Full week name
%b Local Simplified month name
%B Local Full month name
%c Local corresponding date and time representation
%d Day of the one months (01-31)
%H Hours of the day (24-hour, 00-23)
%I Number of hours (12-hour, 01-12)
%j Day of the Year (001-366)
%m Month (01-12)
%M Number of minutes (00-59)
%p The corresponding character of the local AM or PM; use with%i
%s Seconds (01-61)
%u

The number of weeks in a year. (00-53 weeks is the beginning of one weeks.) )

All days before the first Sunday are placed in the No. 0 week

%w The day of the one week (0-6,0 is Sunday)
%W and%u basically the same, the difference is%w with Monday for the start of the week
%x Local corresponding date
%x Local corresponding time
%y The year of the century was removed (00-99)
%Y The full year
%Z The name of the time zone (if it does not exist as a null character)
%% % character
Common Operations
Import TimePrint(Time.localtime ())#returns the struct_time of the current timePrint(Time.localtime (1304575584.1361799))#time.struct_time (tm_year=2011, tm_mon=5, tm_mday=5, tm_hour=14, tm_min=6, tm_sec=24, tm_wday=3, tm_yday=125, tm_ isdst=0)#Convert the timestamp to the struct_time of the current time zone.Print(Time.gmtime ())#similar to LocalTime, Gmtime is the struct_time of converting timestamps to utc+0 time zonesPrint(Time.time ())#returns the timestamp of the current timePrint(Time.mktime (Time.localtime ())) T= (2019, 2, 15,10,13,38,1,48,0)#TupletimePrint(Time.mktime (t))#back to 1550196818.0#Convert a struct_time to a timestampPrint(Time.asctime ())#convert the progenitor or struct_time into the form of "Sun 20 12:30:11 2017"#if there are no arguments, the time.localtime () will be passed in as a parameterPrint(Time.ctime ())#convert timestamp to "Sun 20 12:30:11 2017" formPrint(Time.strftime ('%y-%m-%d%x', Time.localtime ()))#2017-08-20 20:33:15#to convert a struct_time tuple to a formatted time stringPrint(Time.strptime ('2011-05-05 16:37:06',"%y-%m-%d%x"))#time.struct_time (tm_year=2011, tm_mon=5, tm_mday=5, tm_hour=16, tm_min=37, tm_sec=6, tm_wday=3, tm_yday=125, tm_ Isdst=-1)#Convert a formatted time string to a struct_time tuplePrint(Time.sleep (1))#delay the thread for T-seconds execution
1 Import Time2 3Time.sleep (2)4 Print("clock1:%s"% Time.clock ())#return is program run time5Time.sleep (2)6 Print("clock2:%s"% Time.clock ())#return is the time interval from the first time.clock7Time.sleep (2)8 Print("clock3:%s"% Time.clock ())#return is the time interval from the first time.clock
Special Time.clock.

conversion of the expression to each other

Python Basics-Day 5 learning note-Standard library of modules: Time (1)

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.