shell 之时间戳

vim timeforyou.sh

#/bin/bash
##by cc

read -p "Please input yourtime:" time
a=$time
if [ $a != 0 ]
then
date -s "$a" 1>>/dev/null
##获取你的时间戳
time1=`date +%s`
ntpdate time.nist.gov 1>>/dev/null
##获取当前时间戳
time2=`date +%s`
##秒
result_second=$[$time2-$time1]
##分
time3=$[$time2-$time1]
result_min=$[$time3/60]
##时
result_hour=$[$result_min/60]
##日
result_day=$[$result_hour/24]
##周
result_week=$[$result_day/7]
##月
result_moth=$[$result_week/4]

echo "距离当前时间:"
echo "秒" $result_second
echo "分" $result_min
echo "时" $result_hour
echo "日" $result_day
echo "周" $result_week
echo "月" $result_moth
fi

 

posted @ 2017-03-21 19:36  凹凸先生  阅读(4797)  评论(0编辑  收藏  举报