[英]How to increment a date using Arrow?
更新至 2020-07-28
增加一天
now.shift(days=1)
減少一天
now.shift(days=-1)
原答案
自 2019-08-09 起棄用
https://arrow.readthedocs.io/en/stable/releases.html
增加一天
now.replace(days=1)
減少一天
now.replace(days=-1)
文檔指出shift
將用於添加偏移量:
now.shift(days=1)
帶有days
、 hours
、 minutes
等參數的replace
方法似乎和 shift 一樣工作,盡管 replace 也有day
、 hour
、 minute
等參數,這些參數用提供的值替換給定字段中的值。
無論如何,我認為例如now.shift(hours=-1)
比now.replace
清楚得多。
查看文檔
now = arrow.now()
oneDayFromNow = now.replace(days+=1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.