#!/usr/bin/python
# coding: utf-8
import datetime
####### 字符串转日期,并增减计算 ########
behaviour_begin_date = '20210701'
dt = datetime.datetime.strptime(behaviour_begin_date, '%Y%m%d')
# 加2天
out_date = (dt + datetime.timedelta(days=2))
print(out_date)
# 加1小时
out_date = (dt + datetime.timedelta(hours=1))
print(out_date)
# 加xx小时后转特定格式的字符串打印输出
hour_len = 168 # 7*24
for k in range(hour_len):
out_date = (dt + datetime.timedelta(hours=k))
out_date2 = out_date.strftime('%Y%m%d%H')
# 2021070100
print(out_date2)
#具体的年、月、日
#print(str(out_date.year) + str(out_date.month) + str(out_date.day) + str(out_date.hour))
1、python中时间日期格式化符号
https://www.runoob.com/python/att-time-strftime.html