我希望超链接中的第一个 datetime
比第二个日期早 1 天,也就是今天的日期。我阅读了一些关于 timedelta
的内容,但我没有看到它是如何在超链接中应用的。
http://www.nhl.com/stats/rest/skaters?isAggregate=false&reportType=basic&isGame=true&reportName=skatersummary&sort=[ {%22property%22:%22playerName%22,%22direction%22:%22ASC%22}]&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameDate%3E=%22' + datetime.datetime.now().strftime ('%Y-%m-%d'
) + '%22%20and%20gameDate%3C=%22' + datetime.datetime.now().strftime('%Y-%m -%d'
) + '%22%20and%20gameTypeId=2%20and%20gameLocationCode=%22H%22
最佳答案
一些放置得当的括号就足够了:
(datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
友情建议:看看Python string formatting而不是使用连接构造字符串。它最终会变得更干净,重复更少。
关于Python datetime 使用 timedelta 减去 1 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48534114/