bash (Linux) date 命令的有效输入 DATE 格式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30875249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:12:29  来源:igfitidea点击:

What are valid input DATE formats for the (Linux) date command?

linuxbashdatescripting

提问by Xofo

The following command generates the date for the next day:

以下命令生成第二天的日期:

date -d "20150615 12:00 +1 day" +%Y%m%d
20150616

I would like to specify my own INPUT date format, such as:

我想指定我自己的 INPUT 日期格式,例如:

2015_06_15

2015_06_15

But the date command does not like this format and complains about invalid date:

但是 date 命令不喜欢这种格式并抱怨无效日期:

date: invalid date '2015_06_15 12:00 +1 day'

Is it possible to use such a date format? And if so how could I do this.

是否可以使用这样的日期格式?如果是这样,我怎么能做到这一点。

回答by Cyrus

A workaround:

解决方法:

x="2015_06_15"
date -d "${x//_/} 12:00 +1 day" +%Y%m%d

Output:

输出:

20150616