Convert date to format ISO8601 UTC timestamp + ms

72 Views Asked by At

I'm using this command to check the last modify date on the file.

stat -c '%y' TEST_FILE.tar

result in this date format: 2023-08-21 05:16:10.802947000 +0200

However in may bash script i want to display the date with this format ISO8601 UTC timestamp + ms

date --utc +%FT%T.%3NZ  

Expected time in this format: 2023-08-21T03:16:10.854Z

how to get this format?

1

There are 1 best solutions below

0
the busybee On BEST ANSWER

You can use the formatting capability of date:

date -d "`stat -c '%y' TEST_FILE.tar`" +%FT%T.%3NZ

The option -d lets date format the given time, not now. You need the double quotation marks to include the blanks in the argument.