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

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============
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值