且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Unix中获取上个月的最后一天

更新时间:2023-11-23 21:20:04

如果您有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.