- #!/bin/bash
- warning(){
- echo "###################################################"
- echo " Invalid! Please retype. [ Ctrl+C ] to exit!"
- echo "###################################################"
- }
- while :
- do
- read -p "Please enter the 1st date : " datex
- if [[ $datex =~ [0-9]{8}$ ]];then
- break
- else
- warning
- continue
- fi
- done
- while :
- do
- read -p "Please enter the 2nd date : " datey
- if [[ $datey =~ [0-9]{8}$ ]];then
- break
- else
- warning
- continue
- fi
- done
- a=$(date -d $datex +%s)
- b=$(date -d $datey +%s)
- if [ $a -lt $b ];then
- z=$(($b-$a))
- else
- z=$(($a-$b))
- fi
- i=$[$z/86400]
- if [ $i == 1 ];then
- echo "$i day"
- else
- echo "$i days"
- fi
[解析]
输入2个8位的时间日期,然后转换成时间戳,最后相差除以86400(1天的秒数),得到多少天。
阅读(2648) | 评论(0) | 转发(0) |