我有点困惑!我有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