shell 之時間戳

vim timeforyou.shvim

#/bin/bash
##by ccbash

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]blog

echo "距離當前時間:"
echo "秒" $result_second
echo "分" $result_min
echo "時" $result_hour
echo "日" $result_day
echo "周" $result_week
echo "月" $result_moth
fiinput

相關文章
相關標籤/搜索