datetime模块
作者:互联网
from datetime import datetime # print(datetime.now()) # 直接获取当前时间 # print(datetime.utcnow()) # 获取格林威治时间 # dt=datetime.now() # print(dt.year) # print(dt.month) # print(dt.day) # print(dt.hour) #计算时间差 # dt1=datetime(2022,7,8,12,0) # dt2=datetime(2020,5,5,13,0) # print(dt1-dt2) # print(type(dt1)) #把字符串转为datetime时间类型 s1='2022/7/8' ret=datetime.strptime(s1,'%Y/%m/%d') print(ret,type(ret)) #把datetime时间类型转为字符串 dt=datetime(2022,7,8,13,0) ret1=dt.strftime('%Y-%m-%d %H:%M:%S') print(ret,type(ret1))
标签:ret,datetime,模块,print,dt,type,dt1 来源: https://www.cnblogs.com/gm11/p/16461316.html