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

后端 未结 9 1512

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:01

    Taking the other answers one step further, you could add a function to your ~/.bashrc or ~/.zshrc to add the date -I flag:

    date() {
      if [ "$1" = "-I" ]; then
        command date "+%Y-%m-%dT%H:%M:%S%z"
      else
      command date "$@"
      fi
    }
    

提交回复
热议问题