我有點困惑!我有JS將時間段添加/減去當前時間(Javascript)
//Set datetimes for the centre of the Timeline and the highlighting period
var myCurrentDateTime = new Date();
var MS_PER_MINUTE = 60000;
var MinsToDeductForCentre = 1440
var MinsEitherSideOfNow = 720
var myTLcenterdate = new Date(myCurrentDateTime - (MinsToDeductForCentre * MS_PER_MINUTE));
var tldate = myTLcenterdate.toString()
var hlStartDate = new Date(myCurrentDateTime - (MinsEitherSideOfNow * MS_PER_MINUTE));
var hlEndDate = new Date(myCurrentDateTime + (MinsEitherSideOfNow * MS_PER_MINUTE));
myTLcentredate給了我一個日期24小時的以下位當前時間之前
hlStartDate給了我一個日期12小時當前時間
之前,但hlEndDate給人NotANumber錯誤.. 。
它基本上把myCurrentDateTime和MinsEitherSideOfNow * MS_PER_MINUTE(43200000)爲字符串值,並加入他們給予例如 「週四5月17日10點44分17秒UTC + 0100 201243200000」
爲什麼?
你的代碼似乎沒什麼問題。我試了一下,有沒有例外。只需嘗試「alert(」typeof hlEndDate is「+(typeof hlEndDate));」你會得到:「typeof hlEndDate是對象」。所以你的hlEndDate仍然是一個「Date」對象。沒有錯。 – arthur