首页 > 代码库 > shell:bash根据指定日期 获取前一天 和 后一天的日期
shell:bash根据指定日期 获取前一天 和 后一天的日期
####################################################################### Copyright C 2014 ## All rights reserved ## Name: yestoday.sh# Author: Canux canuxcheng@163.com ## Version: V1.0 ## Time: Wed 12 Nov 2014 04:37:37 PM CST# Description: ########################################################################!/bin/bashif [ "$1" = "" ]then DATE_NO=`date +%Y%m%d` CURDAY=`date +%d` CURMONTH=`date +%m` CURYEAR=`date +%Y`else DATE_NO=$1 CURYEAR=`echo $1 | awk ‘{print substr($0,1,4)}‘` CURMONTH=`echo $1 | awk ‘{print substr($0,5,2)}‘` CURDAY=`echo $1 | awk ‘{print substr($0,7,2)}‘`fiLASTYEAR=`expr $CURYEAR - 1`if [[ $((10#$CURMONTH)) -eq 1 ]]then LASTMONTH=12else LASTMONTH=`expr $CURMONTH - 1`fiif [[ $LASTMONTH -ge 1 ]] && [[ $LASTMONTH -le 9 ]]then LASTMONTH=0$LASTMONTHelse LASTMONTH=$LASTMONTHfiNUM1=`cal $LASTMONTH $CURYEAR | awk ‘NR==6{print $NF}‘`NUM2=`cal $LASTMONTH $CURYEAR | awk ‘NR==7{print $NF}‘`NUM3=`cal $LASTMONTH $CURYEAR | awk ‘NR==8{print $NF}‘`if [[ $NUM3 -ne 0 ]]then LMLASTDAY=$NUM3elif [[ $NUM3 -eq 0 ]] && [[ $NUM2 -ne 0 ]]then LMLASTDAY=$NUM2else LMLASTDAY=$NUM1fiif [[ $((10#$CURDAY)) -eq 1 ]] then if [[ $((10#$CURMONTH)) -eq 1 ]] then LASTDATE=$LASTYEAR$LASTMONTH$LMLASTDAY else LASTDATE=$CURYEAR$LASTMONTH$LMLASTDAY fielse LASTDATE=`expr $DATE_NO - 1`fiecho $LASTDATE####################################################################### Copyright C 2014 ## All rights reserved ## Name: tomorrow.sh# Author: Canux canuxcheng@163.com ## Version: V1.0 ## Time: Wed 12 Nov 2014 04:52:14 PM CST# Description: ########################################################################!/bin/bashif [ "$5" = "" ]then CURDATE=`date +%Y%m%d` CURDAY=`date +%d` CURMONTH=`date +%m` CURYEAR=`date +%Y` CURHOUR=`date +%H` CURMIN=`date +%M`else CURDATE=$8 CURYEAR=`echo $2 | awk ‘{print substr($0,1,4)}‘` CURMONTH=`echo $2 | awk ‘{print substr($0,ENDHOUR,2)}‘` CURDAY=`echo $2 | awk ‘{print substr($0,7,2)}‘`fiNEXTYEAR=`expr $CURYEAR + 1`if [[ $((10#$CURMONTH)) -eq 12 ]]then NEXTMONTH=1else NEXTMONTH=`expr $CURMONTH + 1`fiif [[ $((10#$NEXTMONTH)) -ge 1 ]] && [[ $((10#$NEXTMONTH)) -le 9 ]]then NEXTMONTH=0$((10#$NEXTMONTH))else NEXTMONTH=$NEXTMONTHfi#the last day of curent monthNUM1=`cal $CURMONTH $CURYEAR | awk ‘NR==6{print $NF}‘`NUM2=`cal $CURMONTH $CURYEAR | awk ‘NR==7{print $NF}‘`NUM3=`cal $CURMONTH $CURYEAR | awk ‘NR==8{print $NF}‘`if [[ $NUM3 -ne 0 ]]then LASTDAY=$NUM3elif [[ $NUM3 -eq 0 ]] && [[ $NUM2 -ne 0 ]]then LASTDAY=$NUM2else LASTDAY=$NUM1fiif [[ $((10#$CURMONTH)) -eq 12 ]] && [[ $((10#$CURDAY)) -eq 31 ]]then NEXTDATE=${NEXTYEAR}0101elif [[ $((10#$CURDAY)) -eq $((10#$LASTDAY)) ]]then NEXTDATE=${CURYEAR}${NEXTMONTH}01else NEXTDATE=`expr $CURDATE + 1`fiecho $NEXTDATE
shell:bash根据指定日期 获取前一天 和 后一天的日期
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。