因此,如果今天是 2010 年 4 月 12 日,则应返回 2009 年 10 月 1 日
我在谷歌上搜索到的一些可能的解决方案似乎过于复杂,有什么建议吗?
最佳答案
您可以使用两个日期
var date = new Date(2010, 3, 12);
var date6MonthsAgo = new Date(date);
date6MonthsAgo.setMonth(date.getMonth() - 6);
// and to set it to the first date of the month
date6MonthsAgo.setDate(date.getDate() - date.getDate() + 1);
关于JavaScript:获取第一个月前 6 个月日期的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36809010/