Time ():
#设a为字符串
Import time
A = "2011-09-28 10:00:00"
#中间过程, it is generally necessary to convert a string into a time array
Time.strptime (A, '%y-%m-%d%h:%m:%s ')
>>time.struct_time (tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, Tm_wday=1, tm_yday=270, TM_ISDST=-1)
#将 "2011-09-28 10:00:00" to timestamp
Time.mktime (Time.strptime (A, '%y-%m-%d%h:%m:%s '))
>>1317091800.0
#将时间戳转化为localtime
x = Time.localtime (1317091800.0)
Time.strftime ('%y-%m-%d%h:%m:%s ', x)
Timestamps can be added or reduced or compared in size
DateTime ():
Calculate a time difference of two dates:
DateTime ():
A=datetime.timedelta (hours=10)
B=datetime.datetime.now ()
The current time is 10 hours backwards:
(B+a). Strftime ("%y%m%d%h%m%s")
Calculate the specific time difference of two times:
Ff=datetime.datetime (2017,4,9)-datetime.datetime (2017,4,12)
Ff.days
Common use of Python time functions