var d1 = new Date(2015, 4, 31) var d2 = new Date(2015, 4, 32) var d3 = new Date(2015, 4, -1) console.log(d1) console.log(d2) console.log(d3) console.log(d1.getDate(), d1.getMonth() + 1) console.log(d2.getDate(), d2.getMonth() + 1) console.log(d3.getDate(), d3.getMonth() + 1) /* Sun May 31 2015 00:00:00 GMT+0800 (中国标准时间) Mon Jun 01 2015 00:00:00 GMT+0800 (中国标准时间) Wed Apr 29 2015 00:00:00 GMT+0800 (中国标准时间) 31 5 1 6 29 4 */
var d = new Date(2015, -1) var year = d.getFullYear() var month = d.getMonth() + 1 var day = d.getDate() console.log(year, month, day) // 2014 12 1