Home > Back-end >  How can I get an ISO-8601 date in Bash?
How can I get an ISO-8601 date in Bash?

Time:09-19

Well I can get a current ISO-8601 time with date "%Y-%m-T%H:%M:%S%z" command in Bash.
The output was 2022-09-19T00:33:55 0900!
However, I want to get the yesterday since that command output.
I mean I want to get the output like 2022-09-18T00:33:55 0900
Can anyone help me?

CodePudding user response:

Use the --date option, like this:

date --date="yesterday"  "%Y-%m-T%H:%M:%S%z"

Note that instead of writing out that whole format string, you can use -Iseconds, like this:

date --date="yesterday" -Iseconds
  • Related