shell 返回昨天和明天日期
来源:互联网 发布:node.js实战pdf 编辑:程序博客网 时间:2024/05/17 08:30
转自酷勤网,自己略有改动。
#!/usr/bin/kshnowDate=`date + %Y%m%d`echo "今天日期:" $nowDate#返回月份的天数get_mon_days(){ Y=`expr substr $1 1 4` M=`expr substr $1 5 2` r1=`expr $Y \% 4` r2=`expr $Y \% 100` r3=`expr $Y \% 400` case $M in 01|03|05|07|08|10|12) days=31;; 04|06|09|11) days=30;; esac if [ $M -eq 02 ] then if [ r1 -eq 0 -a r2 -ne 0 -o r3 -eq 0 ] then days=29 else days=28 fi fi echo $days}#返回昨天日期get_last_date(){ Y=`expr substr $1 1 4` M=`expr substr $1 5 2` D=`expr substr $1 7 2` YY=`expr $Y - 1` MM=`expr $M - 1` DD=`expr $D - 1` MM=`printf "%02d" $MM` DD=`printf "%02d" $DD` lastMonth=$Y$MM lastMonthDays=`get_mon_days $lastMonth` last_date=$Y$M$DD if [ $D -eq 01 ] then if [ $M -ne 01 ] then last_date=$Y$MM$lastMonthDays fi if [ $M -eq 01 ] then last_date=$YY"1231" fi fi echo $last_date}lastDate=`get_last_date $nowDate`echo "昨天日期:" $lastDate#返回明天日期get_next_date(){Y=$(expr substr $1 1 4)M=$(expr substr $1 5 2)D=$(expr substr $1 7 2)YY=$(expr $Y + 1)MM=$(expr $M + 1)DD=$(expr $D + 1)MM=$(printf "%02d" $MM)DD=$(printf "%02d" $DD)r1=$(expr $Y \% 4)r2=$(expr $Y \% 100)r3=$(expr $Y \% 400)next_date=$Y$M$DDif [ $D -eq 30 ] then case $M in 04|06|09|11) next_date=$Y$MM"01";; esac fi if [ $D -eq 31 ] then next_date=$Y$MM"01" case $M in 12) next_date=$YY"0101";; esac fi if [ $M -eq 02 ] then if [ r1 -eq 0 -a r2 -ne 0 -o r3 -eq 0 ] then if [ $D -eq 29 ] then next_date=$Y$MM"01" fi else if [ $D -eq 28 ] then next_date=$Y$MM"01" fi fi fi echo $next_date}nextDate=`get_next_date $nowDate`echo "明天日期:" $nextDate
0 0
- shell 返回昨天和明天日期
- Shell 的昨天今天和明天
- linux中用shell获取昨天、明天或多天前的日期
- linux中用shell获取昨天、明天或多天前的日期
- linux中用shell获取昨天、明天或多天前的日期
- linux中用shell获取昨天、明天或多天前的日期
- linux中用shell获取昨天、明天或多天前的日期
- linux中用shell获取昨天、明天或多天前的日期
- linux中用shell获取昨天、明天或多天前的日期
- Linux中用shell获取昨天、明天或多天前的日期
- java取得昨天和明天的格式化日期
- 003_001 Python 计算昨天和明天的日期
- Java取昨天、今天和明天的日期并格式化
- js获取日期:昨天今天和明天、后天
- Java获取日期-昨天-明天
- 日期判断昨天、今天、明天
- Shell计算昨天明天函数
- shell 获取昨天日期
- [Android] 对ImageView设置属性scaleType为FIT_START,如何去掉多余空白
- win64bit 汇编程序
- 智能手表Basis B1的腕带能够跟踪用户的心率
- 在开发手机APP之前需要考虑的5个问题
- NiNetworkImageView下载图片,goole地图图片的获取
- shell 返回昨天和明天日期
- MEMS麥克風具降噪、高效能、小尺寸優勢
- Android 网络视频播放
- springFramework 源码学习日记(一)源码下载与编译
- deque queue and priority_queue
- poj1128 Frame Stacking
- ZOJ Problem Set - 1847 The Trip
- msocache是什么文件夹
- HDU 2660 Accepted Necklace (DFS)