shell:bash根据指定日期 获取前一天 和 后一天的日期

####################################################################### Copyright C 2014 ## All rights reserved ## Name: yestoday.sh# Author: Canux [email protected] ## 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 [email protected] ## 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

时间: 2024-11-06 21:55:42

shell:bash根据指定日期 获取前一天 和 后一天的日期的相关文章

php获取指定日期的前一天,前一月,前一年日期

前一天的日期为: date("Y-m-d",strtotime("-1 days",strtotime('2019-08-31'))) 前一月的日期为 date("Y-m-d",strtotime("-1 months",strtotime('2019-08-31'))) 前一年的日期为: date("Y-m-d",strtotime("-1 years",strtotime('2019

获取当前日期前(后)x天的日期

package com.xcfh.util; import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;/** *  * @ClassName: BeforeOrAfterDate *  * @Description: 获得当前输入日期前(后)x天的日期 * @author PineTree * @date 2014年12月29

js获取当前日期、前一天、后一天的日期的例子

<script> function addByTransDate(dateParameter, num) { var translateDate = "", dateString = "", monthString = "", dayString = ""; translateDate = dateParameter.replace("-", "/").replace(&qu

python 获取前一天或前N天的日期

简单实现 import datetime # 获取前1天或N天的日期,beforeOfDay=1:前1天:beforeOfDay=N:前N天 def getdate(self,beforeOfDay): today = datetime.datetime.now() # 计算偏移量 offset = datetime.timedelta(days=-beforeOfDay) # 获取想要的日期的时间 re_date = (today + offset).strftime('%Y-%m-%d')

js计算输入日期的前一天,后一天(上一日,下一日)。兼容safari

//下一天function getNextday(){var today=document.getElementById("lang0").value;var t=new Date(today);var tm=new Date(t.getFullYear(),t.getMonth(),t.getDate()+1); var m='0'+(tm.getMonth()+1);var d='0'+tm.getDate() document.getElementById("lang0

[函数] 日期的前一天YESTERDAY 后一天 TOMORROW

(1)用数组 month[ ] 存储每个月的天数后,通过指针*m里的值做数组下标来选择月末那天的日期: (2)算前一天,日期往后退,所以先减1再赋值:用 --*d; (3)闰年的判断条件:能被400整除,或者能被4整除但不能被100整除. 解释:地球绕太阳一圈,实际上花365.24219天,但公历一年只有365天,所以一年就少算了0.24219天.400年下来,少的日子就很可观了,有(0.24219*400=96.876天),约97天,这些得补上.一个简单的法子就是每4年规定为闰年,闰年要补一天

php 前一天或后一天的日期

代码如下 <?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:"

java获取字符串格式日期向前或向后n天的日期

private void setTilteMessage(){          BaseDao dao = new BaseDao();          String titleData = dao.getLatestData();          dao.closeDB();          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");          try {              Date d

PHP前一天,后一天,日期问题

date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>";     echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";     echo "昨天:",date