时间不显示

Time not displayed

本文关键字:显示 时间      更新时间:2023-09-26
alert("hello");
var d = Date();
//alert(d);
var currHour = d.getHours();
document.write(currHour);
function display1(currHour) {
    if(currHour > 1) {
        alert("good morning");
    } else {
        alert("ok bye" + currHour);
    }
}

hello alert显示fine, date也显示fine,但是currHour没有定义,我不知道我做错了什么?

谢谢。

var d = new Date();

您缺少new关键字。新的(MDN)

示例

根据ECMA-262第15.9.2节,Date构造函数作为函数调用时,returns a String representing the current time (UTC).