> shell编程 >

shell日期与时间戳转换的例子

shell中将日期转换为时间戳的方法,date命令的参数与用法

shell中获取时间戳的方式:
 

date -d “$currentTime” +%s

将一个日期转为时间戳,请参考如下方法:

1、得到当前时间
 

 
currentTime=`date “+%Y-%m-%d %H:%M:%S”`

2、将日期转为时间戳
 

 
currentTimeStamp=`date -d “$currentTime” +%s`
echo $currentTimeStamp
(责任编辑:IT)