`date` command on OS X doesn't have ISO 8601 `-I` option?

后端 未结 9 1582

In a Bash script, I want to print the current datetime in ISO 8601 format (preferably UTC), and it seems that this should be as simple as date -I:

http://ss

9条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-29 20:14

    You could use

    date "+%Y-%m-%d"
    

    Or for a fully ISO-8601 compliant date, use one of the following formats:

    date -u +"%Y-%m-%dT%H:%M:%SZ"
    

    Output:

    2011-08-27T23:22:37Z
    

    or

    date +%Y-%m-%dT%H:%M:%S%z
    

    Output:

    2011-08-27T15:22:37-0800
    

提交回复
热议问题