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).
typo:
%Y-%m-%dT%H:%M:%S.%3NZshould be%Y-%m-%dT%H:%M:%S.%3N%Z(theZneeds to be%Z)... and I think for ISO8601 should be
Z%Z.. ?