Jan 29, 2013 5:12:24 PM 在javascript里面怎么转换为 yyyy-MM-dd HH:mm:ss格式

2025-01-01 17:18:11
推荐回答(3个)
回答1:

function zero(n){
if(n<10){
return '0'+n.toString();
}else{
return n.toString();
}
}
var s='Jan 29, 2013 5:12:24 PM';
var d=new Date(s);
var yyyy=d.getYear();
var mm=d.getMonth()+1;
var dd=d.getDate();
var h=d.getHours();
var m=d.getMinutes();
var s=d.getSeconds();
alert(yyyy+'-'+zero(mm)+'-'+zero(dd)+' '+zero(h)+':'+zero(m)+':'+zero(s));

回答2:

var days=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var today=new Date();
var str= (today.getYear()<1900?1900+today.getYear():today.getYear())+"年" + getDouble([today.getMonth()+1])+"月" +getDouble(today.getDate()) +"日 "+ days[today.getDay()]+"
"+getDouble(today.getHours())+":"+getDouble(today.getMinutes())+":"+getDouble(today.getSeconds());
document.getElementById('datetime').innerHTML=str;

自己写一个了。。。

回答3:

为什么不用java或者标签的格式化转化呢。