日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Shell 获取本月最后一天

發布時間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Shell 获取本月最后一天 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Shell 常用日期計算

      • 日期格式化
      • 獲取當前日期
      • 獲取月初、月末系列
      • 獲取天數系列

在 shell 中,經常要計算各種各樣的日期,將平時常用的計算日期方法記錄了下來

如有不對,請及時指正

日期格式化

將格式為 yyyyMMdd 的日期格式化為 yyyy-MM-dd

curr_date=20220130 curr_month_begin=`date -d "${curr_date}" "+%Y-%m-%d"`

獲取當前日期

獲取今天的日期,格式為 yyyyMMdd

curr_date=`date "+%Y%m%d"` echo $curr_date

獲取月初、月末系列

獲取本月第一天

curr_date=20220130 curr_month_begin=`date -d "${curr_date}" "+%Y%m01"`


獲取本月最后一天

思路:先獲取本月第一天,接著求下月第一天,然后下月第一天減去一天

curr_date=20220130 curr_month_begin=`date -d "${curr_date}" "+%Y%m01"` next_month_begin=`date -d "${curr_month_begin} +1 month" "+%Y%m01"` curr_month_end=`date -d "${next_month_begin} -1 day" "+%Y%m%d"`

獲取上個月第一天

思路:先獲取本月第一天,然后減去一個月

curr_date=20220130 curr_month_begin=`date -d "${curr_date}" "+%Y%m01"` pre_month_begin=`date -d "${curr_month_begin} -1 month" "+%Y%m%d"`


獲取上個月最后一天

思路:先獲取本月第一天,然后減去一天

curr_date=20220130 curr_month_begin=`date -d "${curr_date}" "+%Y%m01"` pre_month_end=`date -d "${curr_month_begin} -1 day" "+%Y%m%d"`

獲取天數系列

獲取本月的天數

思路:求出當月最后一天,然后最后一天的數字即天數

curr_date=20220130 curr_month_begin=`date -d "${curr_date}" "+%Y%m01"` next_month_begin=`date -d "${curr_month_begin} +1 month" "+%Y%m01"` curr_month_end=`date -d "${next_month_begin} -1 day" "+%Y%m%d"` curr_month_days=`date -d "${curr_month_end}" "+%d"`

總結

以上是生活随笔為你收集整理的Shell 获取本月最后一天的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。