linux 常用日期 查询前一天 当月1号 上个月第一条和最后一天 上个月

来源:互联网 发布:eclipse新建java工程 编辑:程序博客网 时间:2024/05/16 09:21
TodayYM=`/bin/date  +%Y-%m`
echo $TodayYM


#当月1号
CurrntMontFirstDay=$TodayYM"-01 00:00:00"
echo $CurrntMontFirstDay
#当月1号转为s
currentSeconds=`date -d "$CurrntMontFirstDay" +%s`
echo $currentSeconds
#上月最后一天,s
secondsLastDay=`expr $currentSeconds - 86400`
echo $secondsLastDay


#上个月月末时间
end_last_month=`date -d @$secondsLastDay "+%Y%m%d"`
echo $end_last_month


#上个月开始时间,拼接
start_last_month=`date -d @$secondsLastDay "+%Y%m"`"01"
echo $start_last_month


#上个月
part_month=`date +%Y-%m -d "-1 month "`
part_month1=`date +%Y%m -d "-1 month "`


#上月1号
LastMontFirstDay=$part_month"-01 00:00:00"
echo $LastMontFirstDay
#上月1号时间s
LastMontFirstDaySeconds=`date -d "$LastMontFirstDay" +%s`
echo $LastMontFirstDaySeconds
#上两个月的月末时间,s
secondsLast2Day=`expr $LastMontFirstDaySeconds - 86400`
echo $secondsLast2Day
#上两个月的月末时间
enddate2=`date -d @$secondsLast2Day "+%Y%m%d"`
echo $enddate2
#上两个月的月初时间
startdate2=`date -d @$secondsLast2Day "+%Y%m"`"01"
echo $startdate2
#上两个月
part_month2=`date +%Y%m -d "-2 month "`
echo $part_month2


#上两个月所属哪一年
myyear=`echo ${part_month2:0:4}`
echo $myyear============
阅读全文
0 0