码迷,mamicode.com
首页 > Web开发 > 详细

Json格式的字符串转换为正常显示的日期格式

时间:2015-08-31 16:51:43      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

//返回自定义格式日期: 2015-07-17 13:53:37
function ChangeDateFormat(jsondate) {
jsondate = jsondate.replace("/Date(", "").replace(")/", "");

if (jsondate.indexOf("+") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("+"));
} else if (jsondate.indexOf("-") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("-"));
}
var date = new Date(parseInt(jsondate, 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}

//返回标准格式的日期:2015-07-17T05:53:37.000Z

function ConvertJSONDateToJSDateObject(JSONDateString) {
var date = new Date(parseInt(JSONDateString.replace("/Date(", "").replace(")/", ""), 10));
return date.toJSON();
}

Json格式的字符串转换为正常显示的日期格式

标签:

原文地址:http://www.cnblogs.com/shuimiao/p/4773087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!