how to format a date in shell script

2019-08-14 13:10发布

问题:

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

回答1:

Try this:

$ date --date='01-SEP-2011' +%Y-%m-%d


回答2:

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


回答3:

kent$  date +%F -d "01-SEP-2011" 
2011-09-01


标签: bash shell