下个月使用date命令? [英] Getting next month with date command?

查看:78
本文介绍了下个月使用date命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自己的一种脚本中拥有了这一点,我确信它已经使用了很长时间了。今天下个月的说法是五月?

I had this in one of my scripts which I'm sure has been working for ages. Today its saying next month is May?

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

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

任何人都知道问题出在哪里-我应该使用更好的下个月脚本吗?

Anyone know what the problem is - is there a better "next month" script I should use?

推荐答案

GNU 手册页:


日期单位的模糊可能导致相关项目出现问题。例如, 2003-07-31 -1 month的计算结果为2003-07-01,因为2003-06-31是无效日期。
为了更可靠地确定上个月,您可以要求提供当月15日之前的月份。

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

您可以使用所有月份都存在的一天:

You can use a day which exists in all months:

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

结果:

April 2014

这篇关于下个月使用date命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆