Python Learning Path-time module

Source: Internet
Author: User

Time module:
1 Import Time2 3 #get timestamp, from 1970 to 1.1 hours to now time, 1970 appear Unix4 Print(Time.time ())5 6 #returns the string pattern of time, which defaults to the current system time7 Print(Time.ctime ())8 Print(Time.ctime (Time.time ()-86400))#number of seconds in 864,001 days9 Ten #return Struct_time object, East eight time, 8 hours earlier than China OneTM =time.gmtime () A Print(tm) - Print(tm.tm_hour,tm.tm_min) -  the #returns the Struct_time object for local time - Print(Time.localtime ()) -  - #convert a struct object to a timestamp + Print(Time.mktime (Time.gmtime ())) -  + #Time delay, in seconds ATime.sleep (5) at Print("%%%%") -  - #Convert a Struct_time object to a string format -TM1 = Time.strftime ("%y-%m-%d%h:%m:%s", Time.gmtime ()) - Print(TM1) - Print(Type (TM1)) in  - #Convert a string format to a struct object toTM2 = Time.strptime ("2016-05-6 15:06","%y-%m-%d%h:%m") + Print(TM2) -  the #convert a struct object to a timestamp * Print(Time.mktime (TM2))

DateTime module:
Import TimeImportdatetime#date format can be directly judged#Output Current date 2017-02-06Print(Datetime.date.today ())#convert timestamps to date formatsPrint(Datetime.date.fromtimestamp (Time.time ()))#output current time, accurate to millisecondsPrint(Datetime.datetime.today ())#convert current time to struct_time formatCurrent_time =Datetime.datetime.today ()Print(Current_time.timetuple ())#Replacement TimePrint(Current_time.replace (1993,7,8,10))#The addition and subtraction of time, Days.seconds.microseconds,milliseconds,minutes,hours,weeksPrint(Datetime.datetime.now () + Datetime.timedelta (days=10))Print(Datetime.datetime.now ()-Datetime.timedelta (days=10))

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