日期:2014-05-20  浏览次数:20739 次

问个JS的转换问题
我从数据库中取得的日期为:/Date(1293811200000+0800)/
现在想求一个JS,该JS能将该日期格式转换成我规定的日期格式:格式参数为:format。
方法应该是类似与
function getNewDate(format, OldDate)
{
}
请问里面要怎么写?注意JS的兼容性问题(支持主流的浏览器)!

------解决方案--------------------
不容易啊。

http://blog.csdn.net/small_love/article/details/5636332

看得我头晕。
------解决方案--------------------
function getNewDate(format, date) {
var mon = two((parseInt(date.getMonth())+1));
var dd = two(parseInt(date.getDate()));
var h = two(parseInt(date.getHours()));
var m = two(parseInt(date.getMinutes()));
var s = two(parseInt(date.getSeconds()));

return format.replace("yyyy", date.getYear()).replace("MM",mon).replace("dd",dd).replace("HH", h).replace("mm", m).replace("ss", s);
}

function two(num) {
if(parseInt(num)<10) {
return "0"+num;
}else {
return num;
}
}