Shell日期处理函数
#上个月 getLastMonth() { month=`date +%m` year=`date +%Y` month=`expr $month - 1` if [ $month -lt 0 ] then month=12 year=`expr $year - 1` fi month=`printf "%02d" $month` #补零 echo $year$month } #获取昨天的日期 YYYYMMDD getLastDate() { day=`date +%d` day=`expr $day - 1` month=`date +%m` year=`date +%Y` if [ $day -lt 1 ] then month=`expr $month - 1` if [ $month -lt 1 ] then year=`expr $year - 1` month=12 fi for loop in 1 3 5 7 8 10 12 #大月 do if [ $loop -eq $month ] then day=31 fi done for loop in 4 6 9 11 #小月 do if [ $loop -eq $month ] then day=30 fi done if [ $month -eq 2 ] #处理2月份天数 then day=28 if [ `expr $year % 400 ` -eq 0 ] #被400整除的闰年 then day=29 elif [ `expr $year % 4` -eq 0 ] #被4整除的闰年 then day=29 if [ `expr $year % 100` -eq 0 ] #被100整除的非闰年 then day=28 fi fi fi month=`printf "%02d" $month` #补零 fi day=`printf "%02d" $day` #补零 echo $year$month$day }
相关推荐
firefaith 2020-10-30
以梦为马不负韶华 2020-10-20
wangzhaotongalex 2020-09-22
jarrygao 2020-11-02
woaimeinuo 2020-10-21
laisean 2020-09-01
libao 2020-09-16
卖口粥湛蓝的天空 2020-09-15
liuyh 2020-08-09
higheels 2020-06-26
thickbookszone 2020-06-14
xiaonamylove 2020-06-14
大牛牛 2020-06-14
firefaith 2020-06-14
bigNoseLiu 2020-06-10
伏雌摘星阁 2020-05-26
laisean 2020-05-09
lishaokang 2020-05-10