from datetime import datetime,timedelta
import time
a = ['2021-05-31', '2021-02-18', '2021-01-26', '2021-01-22', '2021-01-22', '2021-06-28', '2021-06-28', '2021-06-18', '2021-06-01', '2021-05-26', '2021-06-28', '2021-06-28', '2021-06-28', '2021-06-24', '2021-06-21', '2021-03-26', '2021-02-09', '2021-02-09', '2021-02-09', '2021-02-09']
new_time = datetime.now() # 本地时间
one_month = new_time - timedelta(days=14) # 两周前的时间
time_list = []
for i in a:
zx_time = datetime.strptime(i, '%Y-%m-%d')
if one_month < zx_time: # 获取的大于两周前的时间
time_list.append(i)
print(time_list)
时间字符串和本地时间对比
最新推荐文章于 2022-11-12 14:26:40 发布