// 获取半年前时间
let curDate = (new Date()).getTime();
// 将半年的时间单位换算成毫秒
let halfYear = 365 / 2 * 24 * 3600 * 1000;
let pastResult = curDate - halfYear; // 半年前的时间(毫秒单位)
// 日期函数,定义起点为半年前
let pastDate = new Date(pastResult),
pastYear = pastDate.getFullYear(),
pastMonth = pastDate.getMonth() + 1,
pastDay = pastDate.getDate();
let time = pastYear + '-' + pastMonth + '-' + pastDay
03-19
377
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)