I would like to format the date in bash in a script.

The format is: 2016-10-05T12:18:36.890+02:00

I'm currently using: $(date +%Y%m%d%H%M%S)

Any idea how this can be done?

  • 2
    what value do you expect as a result? – RomanPerekhrest Jun 30 '17 at 11:35
  • The current date and time UK (BST). – Berni Jun 30 '17 at 11:47

What you are looking is to format date into ISO 8601 format.

$(date -Is)

I for ISO format, s for datetime.


With GNU date:

$ date +%FT%T.%3N%:z

You can try this one:

date +%Y-%m-%d-T%H:%M:%S%z

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.