加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 用date命令下个月?

发布时间:2020-12-16 01:50:09 所属栏目:安全 来源:网络整理
导读:我在我的一个脚本中有这个,我相信它已经工作了很长时间.今天下个月的说法是五月? #dateMon Mar 31 15:30:13 BST 2014#date +"%B %Y" --date="+1 month"May 2014 任何人都知道问题是什么 – 我应该使用更好的“下个月”脚本吗? 解决方法 从 GNU手册页: The
我在我的一个脚本中有这个,我相信它已经工作了很长时间.今天下个月的说法是五月?

#date
Mon Mar 31 15:30:13 BST 2014

#date +"%B %Y" --date="+1 month"
May 2014

任何人都知道问题是什么 – 我应该使用更好的“下个月”脚本吗?

解决方法

从 GNU手册页:

The fuzz in date units can cause problems with relative items. For example,‘2003-07-31 -1 month’ might evaluate to 2003-07-01,because 2003-06-31 is an invalid date.
To determine the previous month more reliably,you can ask for the month before the 15th of the current month

您可以使用所有月份中存在的日期:

date +"%B %Y" --date="$(date +%Y-%m-15) next month"

结果:

April 2014

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读