初识python 之 小时加减

#!/user/bin/env python
# -*-coding:utf-8 -*-
# author:SimpleSir
# create_time:2023/4/26 10:33
import datetime

deal_hour = '2023061515'
deal_hour_time = datetime.datetime.strptime(deal_hour, "%Y%m%d%H")
last_deal_hour_time = deal_hour_time + datetime.timedelta(hours=-1)
last_deal_hour = last_deal_hour_time.strftime("%Y%m%d%H")
print(last_deal_hour)

结果: 2023061514

posted on 2023-06-15 15:38  Simple-Sir  阅读(35)  评论(0编辑  收藏  举报

导航