#!/bin/bash test.sh

  until
echo "----------------------------------"
echo "请输入您的选择:"
echo "(1) 显示当前时间"
echo "(2) 判断是否是润年"
echo "(3) 时间间隔"
echo "(4) 退出"
echo "----------------------------------"
read input
test $input = 4
do
case $input in
1)
t=` date '+%G-%m-%d %H:%M:%S' `
echo $t
;;
2)
echo -n 请输入将要进行判断的年份:
read year
let "y1=$year % 4"
let "y2=$year % 100"
let "y3=$year % 400"
if [ ! "$y1" -eq 0 ]
then
leap=0
elif [ ! "$y2" -eq 0 ]
then
leap=1
elif [ "$y3" -eq 0 ]
then
leap=1
else
leap=0
fi
if [ "$leap" -eq 1 ]
then
echo "$year 是闰年"
else
echo "$year 不是闰年"
fi
;; 3)
read -p "请输入两个日期,格式(YYYYMMDD YYYYMMDD) :" start end
##将输入的日期转为的时间戳格式
startDate=`date -d "${start}" +%s`
endDate=`date -d "${end}" +%s`
##计算两个时间戳的差值除于每天86400s即为天数差
stampDiff=`expr $endDate - $startDate`
dayDiff=`expr $stampDiff / 86400`
echo $dayDiff
;; 4)echo " (1-4) "
esac
done
05-27 09:23