[英]How to increment a date using Arrow?
Update as of 2020-07-28更新至 2020-07-28
Increment the day增加一天
now.shift(days=1)
Decrement the day减少一天
now.shift(days=-1)
Original Answer原答案
DEPRECATED as of 2019-08-09自 2019-08-09 起弃用
https://arrow.readthedocs.io/en/stable/releases.html https://arrow.readthedocs.io/en/stable/releases.html
Increment the day增加一天
now.replace(days=1)
Decrement the day减少一天
now.replace(days=-1)
The docs state that shift
is to be used for adding offsets:文档指出
shift
将用于添加偏移量:
now.shift(days=1)
The replace
method with arguments like days
, hours
, minutes
, etc. seems to work just as shift does, though replace also has day
, hour
, minute
, etc. arguments that replace the value in given field with the provided value.带有
days
、 hours
、 minutes
等参数的replace
方法似乎和 shift 一样工作,尽管 replace 也有day
、 hour
、 minute
等参数,这些参数用提供的值替换给定字段中的值。
In any case, I think eg now.shift(hours=-1)
is much clearer than now.replace
.无论如何,我认为例如
now.shift(hours=-1)
比now.replace
清楚得多。
See documentation查看文档
now = arrow.now()
oneDayFromNow = now.replace(days+=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.