从箭头获取前一天的日期时间

use*_*827 4 python datetime arrow-python

我可以从箭头获取当前日期时间,如下所示:

arrow.utcnow().date()
Run Code Online (Sandbox Code Playgroud)

或者

arrow.get('2017-02-01').date()
Run Code Online (Sandbox Code Playgroud)

如何获取前一天的日期时间?这不起作用:

arrow.utcnow().date() - 1
Run Code Online (Sandbox Code Playgroud)

或者

 arrow.get('2017-02-01').date() - 1
Run Code Online (Sandbox Code Playgroud)

jer*_*ero 6

谢谢凯卢布。更新是使用shift:

arrow.utcnow().shift(days=-1)
Run Code Online (Sandbox Code Playgroud)

您可以使用替换:

 arrow.utcnow().replace(days=-1)
Run Code Online (Sandbox Code Playgroud)

  • 不推荐使用带有替换的复数值,而是使用“shift”https://arrow.readthedocs.io/en/latest/#replace-shift。这应该变成 arrow.utcnow().shift(days=-1) (2认同)