常用模块-time datetime
time 模块
print(time.strftime('%Y-%m-%d %T')) 2019-11-07 09:28:06
把时间戳转换为日期 print(time.localtime(1533458405.330393))
time.struct_time(tm_year=2018, tm_mon=8, tm_mday=5, tm_hour=16, tm_min=40, tm_sec=5, tm_wday=6, tm_yday=217, tm_isdst=0)
print(time.ctime()) Thu Nov 7 10:06:04 2019
print(time.asctime()) Thu Nov 7 10:06:04 2019
print(time.ctime(1573092481.6335437)) Thu Nov 7 10:08:01 2019
print(time.asctime(time.localtime())) Thu Nov 7 10:08:01 2019
=======================================
datetime 模块
print(datetime.datetime.now()) 2019-11-07 10:17:39.463069获取是哪天
print(datetime.date.fromtimestamp(1234123489)) 2009-02-09
print(datetime.datetime.fromtimestamp(1234123489)) 2009-02-09 04:04:49
获取三天后的时间 print(datetime.datetime.now() + datetime.timedelta(days=3)) 2019-11-10 10:33:17.620146
获取三天前的时间 print(datetime.datetime.now() - datetime.timedelta(days=3)) 2019-11-04 10:36:41.069944
替换时间
obj=datetime.datetime.now()
print(obj.replace(year=2010,month=1))