我正在尝试显示文本“2012 年 10 月 9 日”。相反,它没有运行该功能,而是显示了很多不必要的日期文本。有谁知道我做错了什么?
你可以玩我的 jsfiddle... http://jsfiddle.net/UP3fd/
这是代码...
var myDate = new Date();
convertDate(myDate);
myDate.setFullYear(2012, 9, 9);
document.write(myDate);
function convertDate(d) {
var day = d.getDate();
if (day < 10) {
day = "0" + day;
}
var year = d.getFullYear();
var month = d.getMonth();
var months=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct"," Nov","Dec"];
var currentMonth = months[month];
return (currentMonth + " " + day + ", " + year);
}