how to format a date in shell script

2019-08-14 12:54发布

How can i format the date "01-SEP-2011" on "2011-09-01" format in shell script?

标签: bash shell
3条回答
Emotional °昔
2楼-- · 2019-08-14 13:15

Try this:

$ date --date='01-SEP-2011' +%Y-%m-%d
查看更多
三岁会撩人
3楼-- · 2019-08-14 13:18
kent$  date +%F -d "01-SEP-2011" 
2011-09-01
查看更多
放我归山
4楼-- · 2019-08-14 13:22

If you have Ruby installed on the target system you could do this:

#/bin/bash
read DATE # 01-SEP-2011
set DATE=$(ruby -rdate -e "puts Date.parse('$DATE').to_s")
echo $DATE # 2011-09-01
查看更多
登录 后发表回答