import time import datetime ‘‘‘ print(time.time()) #返回当前系统时间戳 print(time.ctime()) #返回当前系统时间 print(time.ctime(time.time()-86640)) #将时间戳转为字符串格式 print(time.gmtime(time.time()-86640)) #将时间戳转换成struct_time格式 print(time.localtime()) #将时间戳专程从struct_time格式,但返回的本地时间 print(time.mktime(time.localtime())) #与time.localtime()功能相反,将struct_time格式转回成时间戳格式 time.sleep(4) #程序睡眠4秒再执行 print("******") print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))#将struct_time格式转成指定的字符串格式 print(time.strptime("2018-03-06 11:51","%Y-%m-%d %H:%M"))#将字符串格式转换成struct_time格式 ‘‘‘ ‘‘‘ # print(datetime.date.today())#输出格式 2018-03-06 # print(datetime.date.fromtimestamp(time.time()-866400))#2018-02-24将时间戳转为日期格式 # current_time = datetime.datetime.now()# # print(current_time)#输出2018-03-06 14:31:38.781600 # print(current_time.timetuple())#返回struct_time格式 # print(current_time.replace(2017,3,6))#输出2017-03-06 14:53:06.932600,返回当前时间,但指定的值将被替换 # str_to_date = datetime.datetime.strptime("2018/3/6 14:56","%Y/%m/%d %H:%M")#将字符串转换为日期格式 # print(str_to_date) ‘‘‘ # new_date = datetime.datetime.now() + datetime.timedelta(days=10)#比现在增加10天 # new_date = datetime.datetime.now() + datetime.timedelta(days=-10)#比现在减少10天 # new_date = datetime.datetime.now() + datetime.timedelta(hours=-10)#比现在减少10小时 # new_date = datetime.datetime.now() + datetime.timedelta(seconds=120)#比现在增加120秒 # new_date = datetime.datetime.now() + datetime.timedelta(minutes=30)#比现在增加30分钟 # print(new_date)