Import time after calling Time.gmtime () to get standard times
Time.struct_time (tm_year=2016,tm_mon=8,tm_mday=20,tm_hour=6,tm_min=0, tm_sec=0, tm_wday=3, tm_yday= 1, tm_isdst=0)
Call Time.localtime () to get local time (East zone eight)
Time.struct_time (tm_year=2016, tm_mon=8, tm_mday=20, tm_hour=14, tm_min=0, tm_sec=0, tm_wday=3, Tm_yday=1, tm_isdst=0)
Call Time.localtime (1231231322)
Time.struct_time (tm_year=2009, Tm_mon=1, tm_mday=6, tm_hour=16, tm_min=42, tm_sec=2, Tm_wday=1, tm_yday=6, tm_isdst=0)
Compared to 1231231322/3600/24/365 = 39.0421, 1970+39 = 2009
###############################################################################
Struct_time conversion to Timestamp
Time.mktime (x) #x为struct_time格式, for example:
1 Import Time 2 x = Time.localtime (1231231322)3print(time.mktime (x))
Output:
1231231322.0
###############################################################################
Struct_time Convert to formatted time
Time.strftime ("%y-%m-%d%h:%m:%s", x) #x为struct_time格式, separators can be customized, generally used-or:
Output: 2009-01-06 16:42:02
###############################################################################
Format time converted to Struct_time
Time.strptime (' 2016-08-20 14:31:52 ', "%y-%m-%d%h:%m:%s")
Output: Time.struct_time (tm_year=2016, Tm_mon=1, Tm_mday=8, tm_hour=14, tm_min=31, tm_sec=52, tm_wday=4, Tm_yday=8, tm_ ISDST=-1)
###############################################################################
Struct_time converted to Acstime (local time with week and month abbreviation)
Time.asctime (x) #x为struct_time格式
Output: Tue Jan 6 16:42:02 2009
###############################################################################
Timestamp converted to CTime (local time with week and month abbreviation)
Time.ctime (1231231322)
Output: Tue Jan 6 16:42:02 2009
###############################################################################
There is also a datetime module
Datetime.date Date (Month day)
Datetime.time time (hours, minutes, seconds)
Datetime.datetime Date + Time
Datetime.datetime.now () #当前时间
Datetime.datetime.now () + Datetime.timedelta ( -3) #三天前时间
Datetime.datetime.now () + Datetime.timedelta (hours=3) #三小时后时间
Datetime.datetime.now () + Datetime.timedelta (minutes=-2) #两分钟前时间
Datetime.datetime.now () + Datetime.timedelta (Seconds=1) #1秒钟后时间
Python Time module