The usual time functions are as follows
Get Current Date: Time.time ()
Get the timestamp in the form of a tuple: time.local (Time.time ())
Functions formatted with dates (formatted as tuple-based):
(1) Time.asctime (time.local (Time.time ()))
(2) Time.strftime (Format[,t])
To convert a format string to a timestamp:
Time.strptime (str,fmt= '%a%b%d%h:%m:%s%Y ')
Deferred execution: Time.sleep ([secs]), in seconds
Example 1:
#-*-coding:utf-8-*-Import Time#Current TimePrinttime.time ()#time Stamp FormPrintTime.localtime (Time.time ())#easy-to-read formPrintTime.asctime (Time.localtime (Time.time ()))#formatted as 2016-03-20 11:45:39 in the form ofPrintTime.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())#formatted as Sat 28 22:24:24 2016 FormPrintTime.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ())#convert a format string to a timestampA ="Sat Mar 22:24:24"PrintTime.mktime (Time.strptime (A,"%a%b%d%h:%m:%s%Y"))
Output:
1481036968.19time.struct_time (tm_year=2016, tm_mon=12, tm_mday=6, tm_hour=23, tm_min=9, tm_sec=28, tm_wday= 1, tm_yday=341, tm_isdst=23:09:28 20162016-12-06 23:09:2806 23:09:28 20161459175064.0
Example 2: A time is compared with the current, if more than the current time to call a script, or wait half a child to continue to judge
#-*-coding:utf-8-*-Import TimeImportSYSImportOS#determine if the current time exceeds an input timedefFuctime (s):ifTime.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (Time.time ())) >S:returnTrueElse: returnFalse while(1): ifFuctime ('2016-12-05 00:00:00'): #An easy way to invoke a script under a pathOs.system ("python./.. /day_2/prime.py./... /day_2/inti_prime.txt./... /day_2/res_prime.txt") Break Else: Time.sleep (1800) Continue
Python formatted date