#获取国内上一个交易日 def getLastTradingday(): #依赖库 chinese_calendar, datetime dayStep = 1 lastTradingday = datetime.datetime.now() - datetime.timedelta(days=dayStep) while True: if lastTradingday.isoweekday() >= 6 or chinese_calendar.is_workday(lastTradingday) == False: dayStep += 1 lastTradingday = datetime.datetime.now() - datetime.timedelta(days=dayStep) else:
#自定义输出格式化 return lastTradingday.strftime("%Y%m%d")
标签:timedelta,chinese,dayStep,lastTradingday,calendar,datetime,python3 From: https://www.cnblogs.com/jizhi-code/p/17077776.html