获取合约日期

1. 当周星期五

import time,datetime


thisfriday = str(datetime.date.today() + datetime.timedelta(days= (4 - datetime.datetime.now().weekday()))).replace("-", "")
print(thisfriday)

返回

20191025

 

2. 下周星期五

lastfriday = str(datetime.date.today() + datetime.timedelta(days= (11 - datetime.datetime.now().weekday()))).replace("-", "")
print(lastfriday)

返回

20191101

 

上一篇:Python常用模块:date、datetime、calendar


下一篇:python 获取今天、昨天、明天的时间时间戳