I would like to get the current date-time conveniently on the console in standard ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
For example: 2019-07-13T01:09:35Z
I know the date
command displays the current date-time, but not in ISO 8601 format by default. The -I
option shows the date-only portion in standard format. And -Iseconds
displays 2019-07-13T01:18:10+00:00
. That is close, but:
- I would prefer the usual
Z
on the end for an offset of zero, rather than+00:00
. - I would like something shorter to type, for such a basic common task.
My Question here is the same as this one, but for BSD rather than Linux (apparently).
-u
(UTC) otherwise you get the date that seems like UTC but really is in your local timezone. So the full command would bedate -u +"%Y-%m-%dT%H:%M:%SZ"
– wizzard0 Apr 16 '21 at 08:57-u
is needed. The zero-offset time zone is specified by setting theTZ
variable:TZ=GMT
. IMHOUTC
should be used instead because the meaning ofGMT
is a little bit ambiguous. – pabouk - Ukraine stay strong May 06 '22 at 15:28date
ignoredTZ
at least once, and-u
worked flawlessly. Can't recall the exact environment right now tho :/ – wizzard0 May 07 '22 at 17:45