HP UNIX shell_计算任意时刻的上一个时间
没有函数可用,只能自己实现,有问题请回复我
#*****************************#description get last hour#input 2009091812#output 2009091811#*****************************getLastHour(){param=$1#echo "param is:"$parampYear=`echo $param | awk '{ print substr($0,1,4) }'`pMonth=`echo $param | awk '{ print substr($0,5,2) }'`pDay=`echo $param | awk '{ print substr($0,7,2) }'`pHour=`echo $param | awk '{ print substr($0,9,2) }'`#startif [ $pHour = "00" ];thenpHour="23"if [ $pDay = "01" ];thenif [ $pMonth = "01" ];thenpMonth="12"pDay="31"((pYear=$pYear-1))elseif [ $pMonth = "03" ];then((a4=$pYear%4))((a100=$pYear%100))((a400=$pYear%400))if [[ ($a4 = 0 && a100 != 0) || $a400 = 0 ]];then pDay="29"elsepDay="28"fielif [[ $pMonth = "05" || $pMonth = "07" || $pMonth = "10" || $pMonth = "12" ]];thenpDay="30"elsepDay="31"fi((pMonth=$pMonth-1))fielse((pDay=$pDay-1))fielse((pHour=$pHour-1))fi#fomatlen=`echo $pHour | awk '{ print length($0) }'`if [ $len = "1" ];thenpHour="0"$pHourfilen=`echo $pDay | awk '{ print length($0) }'`if [ $len = "1" ];thenpDay="0"$pDayfilen=`echo $pMonth | awk '{ print length($0) }'`if [ $len = "1" ];thenpMonth="0"$pMonthfilastHour="$pYear""$pMonth""$pDay""$pHour"return $lastHour}