对BASH来说是全新的.提前致歉.
Totally new to BASH. Apologies in advance.
问题
我想在特定日期前加上X天.
I'd like to add X days to a specific date.
代码
我发现BASH中的date会检索当前日期.
I figured out that date in BASH retrieves the current date.
我还发现我可以通过以下方式将X天添加到当前日期,
I also figured out that I can add X days to the current date in the following way,
expiration_date=$ date -v +1d给出
Tue Sep 26 20:28:13 CEST 2017实际上是撰写日期加上X=1天.
which is indeed the date of writing plus X=1 days.
问题
我想插入一个要添加X天的特定日期,而不是上面的命令行中的date. 2017年9月20日.
In stead of date in the command line above, I'd like to insert a particular date to which X days will be added, e.g. 20/09/2017.
不在乎特定日期的格式.
Don't care about the format of the particular date.
换句话说:我如何进行以下工作
In other words: How do I make the following work,
expiration_date=$ '20/09/2017' -v +1d
尝试了此答案,但是没有.做我想做的.
Tried this answer, but doesn't do what I want.
不知道OSX会有什么不同.
Did not know things are different for OSX.
推荐答案您可以这样做:
dt='2017-09-20' date -d "$dt +1 day" Thu Sep 21 00:00:00 EDT 2017 date -d "$dt +2 day" Fri Sep 22 00:00:00 EDT 2017
似乎OP正在使用OSX.您可以通过以下方式使用日期添加:
It seems OP is using OSX. You can use date addition this way:
s='20/09/2017' date -j -v +1d -f "%d/%m/%Y" "$s" Thu Sep 21 14:49:51 EDT 2017更多推荐
在BASH中的特定日期添加X天
发布评论