如何在Unix中获取上个月的最后一天 [英] How to get last day of last month in unix
本文介绍了如何在Unix中获取上个月的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取上个月的最后一个日期。
I have the requirement to get the last date of the last month.
今天,最后一天的最后一个日期是30(四月)。
For today the last months last day is 30 (April).
推荐答案
如果您有gnu日期,这应该可以工作:
this should work if you have gnu date:
1 day ago <month> 1
< month>
例如,
kent$ date -d'1 day ago may 1'
Tue Apr 30 00:00:00 CEST 2013
另一个示例,查找7月之前的月份的最后一天:
another example, find the last day of the month before July:
kent$ date -d'1 day ago july 1'
Sun Jun 30 00:00:00 CEST 2013
请注意,时间戳记设置为 00:00:00
。
note that, the timestamp was set to 00:00:00
.
这篇关于如何在Unix中获取上个月的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文