Python Time module

Source: Internet
Author: User

The time module can be used to format dates and times , which are floating-point decimals in seconds. Each timestamp is represented by how long it has been since midnight on January 1, 1970 (the calendar).

The following are some of the time-format conversion functions that are commonly used by times modules. Timestamps can be compared directly to size.

1 Import Time2 3 #If you want to convert time stamps and formatted time to each other, you must first turn into a time tuple before you can turn4 Print(Int (time.time ()))#Current time stamp5 cur_time = Time.strftime ('%y-%m-%d%h:%m:%s ')6Cur_time = Time.strftime ('%h%m%s')#format time to take the current time7Cur_time1 = Time.strftime ('%y-%m-%d')8 print (cur_time1)9 Ten Print(Type (cur_time1)) One Print(Time.gmtime ())#The default is the time tuple of the standard time zone, and if a timestamp is passed, the timestamp is converted to a time tuple.  A Print(Time.timezone)#a few hours apart from the standard time. - Print(Time.gmtime (1516005840))#Standard Time zone.  -Cur_time= Time.localtime (1516005840)#The default is to take the time tuple of the current time zone, and if a timestamp is passed, the timestamp is converted to a time tuple.  theres = Time.strftime ('%y-%m-%d%h:%m:%s', Cur_time) - defTimestamptostr (time_strmp,format='%y%m%d%h%m%s'): -     #time stamp to format good time -Cur_time = Time.localtime (TIME_STRMP)#time stamp into a time tuple +res = time.strftime (format, cur_time)#and then turn the time tuple into a well-formatted time. -     returnRes + defStrtotimestamp (time_st,format='%y%m%d%h%m%s'): A     #20181128113859 at     #This function is a well-formed time, a time-stamped -T=time.strptime (Time_st,format)#turn formatted time into a time tuple -res = Time.mktime (t)#time-tuple into timestamp -     returnRes -  -t = Timestamptostr (Time.time (),'%y-%m-%d') in Print(t) -T1 = Strtotimestamp (t,format='%y-%m-%d') to Print(t1) + Print(Type (t1)) - #86400 * 3 #3天 the #32342-86400 * 3 #3天前

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