这个答案和评论提到--rfc-3339了一个“隐藏”--iso-8601选项,我已经使用了很长时间,现在似乎没有记录。
该选项文档何时从--help文本中删除?
该选项会很快消失吗?
Ant*_*hon 113
该选项date于 1999 年(4 月 8 日)在 coreutils (可能就是您所拥有的)中引入。
该文档在2005 年被删除,在提交中没有太多解释。
在2011,对于--iso-8601的帮助下重新与下面的解释:
We deprecated and undocumented the --iso-8601 (-I) option mostly
because date could not parse that particular format. Now that
it can, it's time to restore the documentation.
* src/date.c (usage): Document it.
* doc/coreutils.texi (Options for date): Reinstate documentation.
Reported by Hubert Depesz Lubaczewski in http://bugs.gnu.org/7444.
Run Code Online (Sandbox Code Playgroud)
看起来帮助已在 5.90 版中取出并在 8.15 版中放回(它不在我的 8.13 版中),上面的评论表明它现在又回来了,不太可能很快消失。
在 8.31 版(由 Solus 2020 年 7 月提供)中,两个选项的手册页描述是:
-I[FMT], --iso-8601[=FMT]
output date/time in ISO 8601 format. FMT='date' for date only (the default), 'hours', 'minutes', 'sec?
onds', or 'ns' for date and time to the indicated precision. Example: 2006-08-14T02:34:56-06:00
--rfc-3339=FMT
output date/time in RFC 3339 format. FMT='date', 'seconds', or 'ns' for date and time to the indicated
precision. Example: 2006-08-14 02:34:56-06:00
Run Code Online (Sandbox Code Playgroud)
Pád*_*ady 49
--help 最近实际上得到了更新,因此该选项绝对不会消失:
-I[FMT], --iso-8601[=FMT] output date/time in ISO 8601 format.
FMT='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14T02:34:56-06:00
-R, --rfc-2822 output date and time in RFC 2822 format.
Example: Mon, 14 Aug 2006 02:34:56 -0600
--rfc-3339=FMT output date/time in RFC 3339 format.
FMT='date', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14 02:34:56-06:00
Run Code Online (Sandbox Code Playgroud)
请注意,由于 coreutils-8.27--rfc-2822已被弃用,以支持更通用的--rfc-email
-R, --rfc-email output date and time in RFC 5322 format.
Example: Mon, 14 Aug 2006 02:34:56 -0600
Run Code Online (Sandbox Code Playgroud)
alf*_*era 34
I'm running Linux Mint and the option is available:
$ lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 17.3 Rosa
Release: 17.3
Codename: rosa
Run Code Online (Sandbox Code Playgroud)
The execution of the command:
$ date --iso-8601=seconds
2016-12-14T09:53:25-0400
Run Code Online (Sandbox Code Playgroud)
An alternative that appends the Z at the end:
$ echo "$(date --iso-8601=seconds)Z"
2021-06-14T23:26:06+00:00Z
Run Code Online (Sandbox Code Playgroud)
rou*_*ble 20
对于独立于平台、(几乎)完全兼容的 ISO 8601 日期,请使用以下内容:
date +"%Y-%m-%dT%H:%M:%S%z"
Run Code Online (Sandbox Code Playgroud)
这将导致如下时间: 2021-01-16T23:09:44-0500
这应该适用于 BSD 和 Linux。
从技术上讲,为了完全合规,它应该是:
date +"%Y-%m-%dT%H:%M:%S%:z"
Run Code Online (Sandbox Code Playgroud)
(注意偏移量有一个冒号它。)这将导致一个时间,如:2021-01-16T23:09:44-05:00
但这在 Mac OSX 上不起作用(在撰写本文时)。
对于UTC时间(零偏移),您可以使用(注意-u):
date -u +"%Y-%m-%dT%H:%M:%SZ"
Run Code Online (Sandbox Code Playgroud)
这将导致如下时间: 2021-01-17T04:16:14Z
| 归档时间: |
|
| 查看次数: |
118295 次 |
| 最近记录: |