How to get ISO 8601 date format – yyyy-MM-dd T HH:mm:ss Z – printed in bash?
There is an option built-in provided in the bash shell to print the date format in yyyy-MM-dd T HH:mm:ss Z (with the offset from UTC, such as UTC+05:30 for India).
This will format ‘date’ for date only (the default), ‘hours’, ‘minutes’, ‘seconds’, or ‘ns’ for date and time
From bash – date man page-I[FMT], –iso-8601[=FMT]
output date/time in ISO 8601 format. FMT=’date’ for date only (the default), ‘hours’, ‘minutes’, ‘seconds’, or ‘ns’ for date and time to the indicated precision. Example:
An example output would look like this:
[email protected]:~$ date -Is 2022-08-14T07:57:27+05:30
You may also refer to other most popular date printing formats in bash: