time 模块常用
print(time.asctime()) #参数是time tuple,如果不给time tuple就返回当前时间 返回时间格式"Fri Aug 19 11:14:16 2016
time.localtime()
time.struct_time(tm_year=2017, tm_mon=2, tm_mday=18, tm_hour=14, tm_min=21, tm_sec=47, tm_wday=5, tm_yday=49, tm_isdst=0)
time.strftime() print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()) ) # 将utc struct_time格式转成指定的字符串
import datetime
print(datetime.datetime.now()) #返回 2016-08-19 12:47:03.941925
print(datetime.date.fromtimestamp(time.time()) ) # 时间戳直接转成日期格式 2016-08-19
print(datetime.datetime.now() )
常用 时间加减
print(datetime.datetime.now() + datetime.timedelta(3)) #当前时间+3天
print(datetime.datetime.now() + datetime.timedelta(hours=3)) #当前时间+3小时
print(datetime.datetime.now() + datetime.timedelta(minutes=30)) #当前时间+30分