shell 脚本以 --rfc-3339 格式增加时间

shell scripts to increment time in --rfc-3339 format

我想以 -rfc-3339 格式增加时间并使用了以下命令:

`date --date="(date --rfc-3339=seconds) + 5 minutes"` 

但在将当前时间增加 5 分钟后,它会以标准格式显示增加的系统时间:

Thu Feb 2 20:06:30 IST 2017

我想要 --rfc-3339 格式的所需输出,即

2017-02-02 20:06:30+05:30

提前致谢。

这很简单。 --rfc-3339 标志告诉 date 命令如何格式化它的输出,但是你把它放在 inside input date — 要格式化的日期。

听从您的指挥

date --date="(date --rfc-3339=seconds) + 5 minutes"

--date="stuff" 部分告诉命令您要显示哪个日期(与 "right now" 的默认值相反)。它 看起来 就像您可能正在用 "take the current date and add five minutes" 做某种数学运算,但实际上 () 中的部分不是有效输入,会被忽略。你可以说 date --date="(colorless green ideas sleep furiously) + 5 minutes",你会得到相同的结果 — 或者只是 date --date="+5 minutes".

当然,这是标准输出格式。要以 RFC 3339 格式获取它,只需添加该标志,outside 输入日期字符串:

date --date="+5 minutes" --rfc-3339=seconds

好了。