时间js转换方法Date("149...") 转成 2016-7-12 21:23:34 009

 function timeFormatter(value) {
    var da = new Date(parseInt(value.replace("/Date(", "").replace(")/" , "").split( "+")[0]));
    return da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate();
//     + " " + da.getHours() + ":" + da.getMinutes() + ":" + da.getSeconds();
}
 
 
 
//多种返回格式

function getDate(tm,type) {

var needdate = "";
var date = new Date();
if (tm) {
date = new Date(parseInt(tm.replace("/Date(", "").replace(")/", "").split("+")[0]));
}

var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (day >= 1 && day <= 9) {
day = "0" + day;
}

if (minutes >= 1 && minutes <= 9) {
minutes = "0" + minutes;
}
if (hours >= 1 && hours <= 9) {
hours = "0" + hours;
}
if (seconds >= 1 && seconds <= 9) {
seconds = "0" + seconds;
}


if (type == '2')
{
needdate = hours + ':' + minutes + ':' + seconds;
} else {
needdate = year + '-' + month + '-' + day;
}
return needdate;
}

posted @ 2016-07-12 21:23  李文平  阅读(174)  评论(0编辑  收藏  举报