shell时间转换脚本

字符串转换为时间戳:

time2utc

#!/bin/sh

Time=$1

date -d "${Time}" '+%s'

时间戳转日期字符串

utc2time

#!/bin/sh

UTCTime=$1

len=`expr length ${UTCTime}`

if [ $len -gt 10 ];then
        UTCTime=`expr substr ${UTCTime} 1 10`
fi;

date -d "@${UTCTime}" '+%Y-%m-%d %H:%M:%S'

猜你喜欢

转载自www.cnblogs.com/alter888/p/9272672.html