Python对时间数据进行运算
作者:互联网
目录
导入库
from datetime import datetime
from datetime import timedelta
例子的简单运算
time1= '2019-12-15 00:00:01' # 字符串 日期
print('time1:',time1)
print('d1:',type(time1))
d1 = datetime.strptime(str(time1),'%Y-%m-%d %H:%M:%S')
print('d1:',d1)
print('d1:',type(d1))
plus= d1 + timedelta(days=1) # 加
print('+:',plus)
minus = d1 - timedelta(days=1) # 减
print('-:',minus )
例子的结果
标签:运算,timedelta,Python,time1,datetime,例子,print,数据,d1 来源: https://blog.csdn.net/weixin_45288557/article/details/112102993