Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用箭头增加日期?_Python_Datetime_Arrow Python - Fatal编程技术网

Python 如何使用箭头增加日期?

Python 如何使用箭头增加日期?,python,datetime,arrow-python,Python,Datetime,Arrow Python,我正在使用模块处理Python中的datetime对象。如果我得到这样的当前时间: now = arrow.now() …如何将其增加一天?从2020-07-28更新 增加一天的时间 now.shift(days=1) now.shift(days=-1) now.replace(days=1) now.replace(days=-1) 减少一天的次数 now.shift(days=1) now.shift(days=-1) now.replace(days=1) now.rep

我正在使用模块处理Python中的
datetime
对象。如果我得到这样的当前时间:

now = arrow.now()

…如何将其增加一天?

从2020-07-28更新

增加一天的时间

now.shift(days=1)
now.shift(days=-1)
now.replace(days=1)
now.replace(days=-1)
减少一天的次数

now.shift(days=1)
now.shift(days=-1)
now.replace(days=1)
now.replace(days=-1)

原始答案

截至2019-08-09年已弃用

  • 0.14.5(2019-08-09)[变更]删除了不推荐的更换轮班功能。希望将多个属性传递给replace函数以转换值的用户应改用shift
  • 0.9.0(2016-11-27)[修复]单独的更换和换档功能
增加一天的时间

now.shift(days=1)
now.shift(days=-1)
now.replace(days=1)
now.replace(days=-1)
减少一天的次数

now.shift(days=1)
now.shift(days=-1)
now.replace(days=1)
now.replace(days=-1)

请参见

shift
用于添加偏移的状态:

now.shift(天数=1)

replace
方法使用诸如
days
hours
minutes
等参数,似乎与shift一样工作,不过replace也有
day
hour
minute
等参数,这些参数将给定字段中的值替换为提供的值


无论如何,我认为例如
now.shift(hours=-1)
now更清晰。根据高度推荐的文档进行替换
replace

只会改变属性,而
shift
会相对移动属性。
replace
没有
days
属性,但有
day
将日期更改为给定值。当
shift
是正确的解决方案时,为什么这是公认的答案?@nik您肯定知道自己问题的答案。事情变了。但是,如果您熟悉文档,但不熟悉更改日志,您可以在此处找到api的更改时间:。感谢您的更新--这有助于今晚的快速提醒:-)奇怪的是,
替换
不再知道
小时
分钟
。现在的方法是
now.shift(days=1)
,正如您正确回答的那样。