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 coreutilsHomebrew 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
3in%3Nspecifies that the fractional seconds (nanoseconds) should only be displayed to three decimal places (milliseconds).
Thanks for this gist. It's a shame that the macOS version doesn't support finer granularity than seconds.