嘗試將日期添加到日期值時,出現奇怪的輸出。Javascript setdate getDate()+ 28返回錯誤
var startdate = $("#JobStartDate").val();
startdate = new Date(startdate);
startdate28 = startdate.setDate(startdate.getDate()+28);
console.log(startdate);
console.log(startdate28);
結果
startdate = "Date 2017-03-15T00:00:00.000Z"
startdate28 = 1489536000000
任何想法,我要去的地方錯了嗎?
'startdate.getDate()+ 28'將讓你以毫秒爲單位的時間+ 28 – Weedoze
更確切地說,'setDate'返回毫秒,但還設置了日期* * – adeneo
['setDate()'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)更改基礎日期對象然後返回自從01.01.1970 UTC – Andreas