"Python Route 25" module

Source: Internet
Author: User
Tags deprecated local time

One, Time module

1, Time.sleep (5) #等待5秒钟

# !usr/bin/env python # -*-coding:utf-8-*- Import  Time Print ('start to sleep .... ' ) Time.sleep (5)  # wait 5 seconds for print('wake up ..... ')
#!usr/bin/env python#-*-coding:utf-8-*-Import TimePrint(Time.clock ())#returns processor Time, 3.3 deprecatedPrint(Time.process_time ())#returns processor Time, 3.3 deprecatedPrint(Time.time ())#return timestamp, January 1, 1970 0:00 to now how many seconds, all system timestamps are timed from that timePrint(Time.ctime (Time.time ()))#Converts a timestamp into a string, Thu Feb 10:10:20Print(Time.ctime (Time.time () -24*60*60))#Convert time to string, yesterday at this time, Thu Feb 10:10:20Print(Time.gmtime (Time.time ()))#returns the Time.struct_time object, which can be extracted from month to day secondsPrint(Time.localtime (Time.time ()))#returns the Time.struct_time object, which displays the local time, which can be extracted by the datePrint(Time.mktime (Time.localtime (Time.time ())))#Converts Time.struct_time objects to timestamps, in contrast to the localtime functionPrint(Time.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (Time.time ())))#Convert a Time.struct_time object to a string formatPrint(Time.strptime ('2017-2-16 11:40:27','%y-%m-%d%h:%m:%s'))#Convert A string to a Time.struct_time object
#!usr/bin/env python#-*-coding:utf-8-*-#usage of time.gmtime ()#usage of time.localtime ()ImportTimetime_object=Time.gmtime (Time.time ())Print(Time_object)#time.struct_time (tm_year=2017, tm_mon=2, tm_mday=16,#tm_hour=2, tm_min=35, tm_sec=54, tm_wday=3, tm_yday=47, tm_isdst=0)Time_str ='%s-%s-%s%s:%s:%s'%(time_object.tm_year,time_object.tm_mon,time_object.tm_mday,time_object.tm_hour,time_object.tm_min,time_ OBJECT.TM_SEC)Print(TIME_STR)#2017-2-16 2:45:26 GMT

"Python Route 25" module

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