var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
document.write(n + getDate + getFullYear);


我无法显示当前日期。任何帮助都会有所帮助。

最佳答案

看起来问题出在您对document.write的调用中。您需要在创建的日期对象上调用getDate和getFullYear(d)。见下文



var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
document.write(n + ', ' + d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear());

关于javascript - 用Javascript显示当前日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32417636/

10-12 06:23