For mac OS, the date
utility doesn't give the right information. In that case, use homebrew to install the GNU date utility:
brew install coreutils
Homebrew will install the utility as gdate
instead of date
, which leaves the original date
untouched and available.
gdate
has an --iso-8601
option available, but it doesn't give a timestamp that strictly follows the ISO 8601 standard, as far as I can determine. I find it better to explicitly state the format with:
gdate -u +'%Y-%m-%dT%H:%M:%S.%3NZ'
Two things to not about the format string:
- The
3
in%3N
specifies that the fractional seconds (nanoseconds) should only be displayed to three decimal places (milliseconds).
typo:
%Y-%m-%dT%H:%M:%S.%3NZ
should be%Y-%m-%dT%H:%M:%S.%3N%Z
(theZ
needs to be%Z
)... and I think for ISO8601 should be
Z%Z
.. ?