#coding=utf8
from datetime import date,time,datetime,timedelta
#显示当前日期
print(date.today())
#显示当前日期时间,today与now效果一致。
print(datetime.today())
print(datetime.now())
#字符串转日期时间格式
before_time = datetime.strptime('20210201110000','%Y%m%d%H%M%S')
print(before_time,type(before_time))
#日期时间格式转字符串
current_time = datetime.today()
str_time = current_time.strftime('%Y%m%d %H:%M:%S')
或:datetime.strftime(datetime.now(),'%Y%m%d %H:%M:%S')
print(str_time,type(str_time))
#日期时间差
differ_time = datetime.now()-before_time
print(differ_time)
#日差
print(differ_time.days)
#秒差
print(differ_time.seconds)
#微秒差
print(differ_time.microseconds)
#延迟多久:timedelta(days=..., seconds=..., microseconds=..., milliseconds=..., minutes=..., hours=..., weeks=...)
#当前时间延迟1天
print(datetime.today()+timedelta(days=1))
#当前时间延迟1小时
print(datetime.today()+timedelta(hours=1))