Combined date and time representation in Bash

Misha Slyusarev picture Misha Slyusarev · Oct 24, 2013 · Viewed 21.3k times · Source

How can I obtain current date in the following format using Bash

YYYY-MM-DDThh:mm:ss

Answer

fedorqui 'SO stop harming' picture fedorqui 'SO stop harming' · Oct 24, 2013

With these options:

$ date "+%Y-%m-%d %H:%M:%S"
2013-10-24 10:40:12

or even (thanks Birei!)

$ date "+%F %T"
2013-10-24 10:40:12

All format controls can be get from man date.

I don't know what your T means, but for example you have:

$ date "+%F %T %Z"
2013-10-24 10:40:12 CEST