开发者

how to format a date in shell script

开发者 https://www.devze.com 2023-04-06 06:19 出处:网络
How can i format the date \"01-SEP-2011\" on \"2011-09-01\" format in shell开发者_如何学C script?Try this:

How can i format the date "01-SEP-2011" on "2011-09-01" format in shell开发者_如何学C script?


Try this:

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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消