我的一个脚本中就有这个,我确信它已经工作了很长时间。今天它说下个月是五月?
#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
关于bash - 使用 date 命令获取下个月?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22764358/