0
我有以下JS代碼:setMinutes不gettng預期的結果
// set a date time say 2 Oct
var localTime = new Date(2016, 9, 2, 4, 0, 0);
// set time to 23:59:59
localTime.setHours(23, 59, 59, 0);
console.log(localTime); // // Sun Oct 02 2016 23:59:59 GMT+0800 (MYT), which is expected
// now minus 600 minutes, which should be 10 hours
localTime.setMinutes(-600);
console.log(localTime); // Sun Oct 02 2016 13:00:59 GMT+0800 (MYT)
當我減去從那個時候600分鐘,我也期待着零下10小時,這應該是13時59分59秒,但它的印刷13:00:59
這是什麼我在這裏失蹤?
感謝@Dymos,這導致我正確地做到這一點localTime.setMinutes(localTime.getMinutes() - 600); –