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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM