将javascript日期设置为静态

时间:2015-03-07 14:53:16

标签: javascript date static

如何让这段代码给我一个静态日期?就像我在2015年12月10日2015年12月10日上发布的东西来显示该日期,而不是当前日期。

        var d = new Date();
var months = new Array ("Ianuarie","Februarie", "Martie","Aprilie","Mai","Iunie","Iulie","August","Septembrie","Octombrie","Noiembrie","Decembrie");
var day = d.getUTCDay();
var  month = months[d.getUTCMonth()];
var hour = d.getUTCHours();
var year = d.getUTCFullYear();
if(hour < 10) {
    hour = "0" + hour;
}
var minutes = d.getUTCMinutes();
if (minutes < 10) {
    minutes = "0" + minutes;
}
document.getElementById("date").innerHTML = ("Postat pe " + day + " " + month + " la ora " + hour + ":" +  minutes + " | " + year ).toString(); 

1 个答案:

答案 0 :(得分:2)

尝试这样的事情(例如,如果您的日期是“10/10/2004”):

var d = new Date("10/10/2004")