Search code examples
bashdatetimeiso8601

Combined date and time representation in Bash


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

YYYY-MM-DDThh:mm:ss


Solution

  • 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