//适用于ie以及火狐等浏览器
function toDate(date) {
if(date!=null){
var y = date.getFullYear();
var m = date.getMonth()+1;
m = m<10?'0'+m:m;
var s = date.getSeconds();
var d = date.getDate();
d = d<10?("0"+d):d;
var h = date.getHours();
h = h<10?("0"+h):h;
var M = date.getMinutes();
M = M<10?("0"+M):M;
var S = date.getSeconds();
S = S<10?("0"+S):s;
var str = y+"-"+m+"-"+d+" "+h+":"+M;
return str;
}else{
return "";
}
}
//使用
var mydate = new Date();
var formatDate = toDate(mydate);//显示的日期格式是yyyy-mm-dd hh:mm
本文介绍了一个用于将日期转换为特定格式的JavaScript函数,适用于IE及Firefox等浏览器。通过实例展示了如何在网页中使用该函数来显示日期。
184

被折叠的 条评论
为什么被折叠?



