栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在bash中转换日期格式

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在bash中转换日期格式

#since this was yesterdaydate -dyesterday +%Y%m%d#more precise, and more recommendeddate -d'27 JUN 2011' +%Y%m%d#assuming this is similar to yesterdays `date` question from you #http://stackoverflow.com/q/6497525/638649date -d'last-monday' +%Y%m%d#going on @seth's comment you could do thisDATE="27 jun 2011"; date -d"$DATE" +%Y%m%d#or a method to read it from stdinread -p "  Get date >> " DATE; printf "  AS YYYYMMDD format >> %s"  `date-d"$DATE" +%Y%m%d`#which then outputs the following:#Get date >> 27 june 2011   #AS YYYYMMDD format >> 20110627#if you really want to use awkecho "27 june 2011" | awk '{print "date -d""$1FS$2FS$3"" +%Y%m%d"}' | bash#note | bash just redirects awk's output to the shell to be executed#FS is field separator, in this case you can use $0 to print the line#But this is useful if you have more than one date on a line

有关日期的更多信息

请注意,这仅适用于GNU日期

我读过:

-d
可以通过替换sunfreeware.com版本的日期来解决无法支持的Solaris版本的日期



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/400899.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号