linux中Shell日期转为时间戳的方法
摘要:shell中获取时间戳的方式为:date-d“$currentTime”+%s$date-d@13377434856...
shell中获取时间戳的方式为:date -d “$currentTime” +%s
$ date -d @1337743485671 "+%c"
Sun 28 May 44361 12:41:11 PM CST
如果要将一个日期转为时间戳,方式如下:
1、得到当前时间
currentTime=`date “+%Y-%m-%d %H:%M:%S”`
2、将日期转为时间戳
currentTimeStamp=`date -d “$currentTime” +%s`
echo $currentTimeStamp
3.字符串转换为时间戳可以这样做:
date -d "2010-10-18 00:00:00" +%s
输出形如:
1287331200
其中,-d参数表示显示指定的字符串所表示的时间,+%s表示输出时间戳。
4.而时间戳转换为字符串可以这样做:
date -d @1287331200
输出形如:
Mon Oct 18 00:00:00 CST 2010
【linux中Shell日期转为时间戳的方法】相关文章:
★ Linux中Fedora 17中文字体显示点阵状的解决方法
★ Linux下将Mysql和Apache加入到系统服务里的方法