时间分为三种模式(time 模块)
-
时间戳 (time.time())
-
格式化字符串 (time.strftime(%Y-%m-%d %H:%M:%S %p))
-
结构化的时间对象 (time.localtime() time.gmtime())
import time print(time.localtime()) print(time.localtime().tm_hour) print(time.localtime().tm_wday) print(time.localtime().tm_yday) print(time.gmtime()) #时间转换 #时间戳---->struct_time------->格式化的字符串 import time struct_time=time.localtime(123123) print(struct_time) print(time.strftime('%Y-%m-%d',struct_time)) #格式化的字符串---->struct_time------->时间戳 struct_time=time.strptime('2017-03-11','%Y-%m-%d') print(struct_time) print(time.mktime(struct_time)) import datetime #datetime模块 print(datetime.datetime.now()) print(datetime.datetime.fromtimestamp(1231231)) print(datetime.datetime.now() + datetime.timedelta(days=3)) print(datetime.datetime.now() - datetime.timedelta(days=3)) print(datetime.datetime.now() + datetime.timedelta(days=-3)) print(datetime.datetime.now() + datetime.timedelta(days=3,hours=3))