Js将日期型转换成字符串

十分精简的一个获取当前时间日期的一段JS:

function addZero(v){if(v<10)return '0'+v;return v.toString()}
    var d = new Date();
    var s = d.getFullYear().toString() + addZero(d.getMonth() + 1) + addZero(d.getDate()) + addZero(d.getHours()) + addZero(d.getMinutes()) + addZero(d.getSeconds());


字符串转换为日期:

var str ='2012-08-12 23:13:15';
str = str.replace(/-/g,"/");
var date = new Date(str );
alert(date);


你可能感兴趣的:(web前端,javascript,web前端,javascript)