您的位置:首页 > Web前端 > JavaScript

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

2016-07-12 21:23 363 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: