Python's calculation of time, temporal module

Source: Internet
Author: User
Tags string format timedelta

Import Timetime.sleep (5) #以秒为单位暂停print (Time.clock ()) # returns processor Time, 3.3 obsolete, changed to Time.process_time () measuring processor time, excluding sleep time , unstable, can't be measured on Mac print (Time.altzone) # Returns the time difference from UTC time, in seconds the print (Time.asctime ()) # return format "Fri 11:14:16", Print ( Time.localtime ()) # Returns the struct time object format for local times print (Time.gmtime (Time.time ()-800000)) # Returns the Struc Time Object format for UTC time Print ( Time.asctime (Time.localtime ())) # Returns the time format "Fri 11:14:16", Print (Time.ctime ()) # return Fri 19 12:38:29 2016 format, Ditto # Date string to timestamp string_2_struct = Time.strptime ("2016/05/22", "%y/%m/%d") # Turn date string into struct time object format print (string_2_struct ) Struct_2_stamp = Time.mktime (string_2_struct) # Converts the struct time object to timestamp print (struct_2_stamp) # Converts the timestamp to the string format print ( Time.gmtime (Time.time ()-86640) # convert UTC timestamp to struct_time format print (Time.strftime ("%y-%m-%d%h:%m:%s", Time.gmtime ()) # Converts the UTC struct_time format to the specified string format # time plus minus import datetimeprint (Datetime.datetime.now ()) # returns 2016-08-19 12:47:03.941925print ( Datetime.date.fromtimestamp (Time.time ())) # Timestamp goes directly to date format 2016-08-19print (Datetime.datetime.now ()) print (Datetime.datetime.now () + Datetime.timedelta (3)) # Current time + 3 days print ( Datetime.datetime.now () + Datetime.timedelta (-3)) # Current time-3 days print (Datetime.datetime.now () + Datetime.timedelta (hours= 3) # Current time + 3 hours print (Datetime.datetime.now () + Datetime.timedelta (minutes=30)) # Current time +30 min #c_time = Datetime.datetime.now () print (C_time.replace (minute=3, hour=2)) # time replacement

  

Python's calculation of time, temporal 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.