linux中Shell日期转为时间戳
linux中Shell日期转为时间戳我们可以直接利用date函数就可以搞定了,具体的方法如所示,希望例子能帮助到各位同学.
shell中获取时间戳的方式为:date -d [$currentTime] +%s,如果要将一个日期转为时间戳,方式如下.
1、得到当前时间:
currentTime=`date [+%Y-%m-%d %H:%M:%S]`
2、将日期转为时间戳:
currentTimeStamp=` date -d [$currentTime] +%s` --phpfensi.com echo $currentTimeStamp 3.字符串转换为时间戳可以这样做:
date -d "2010-10-18 0" +%s
其中,-d参数表示显示指定的字符串所表示的时间,+%s表示输出时间戳.
输出形如:Mon Oct 18 0 CST 2010.
查看更多关于linux中Shell日期转为时间戳 - linux教程的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did22305