格式化Json传递的日期
2014-11-19 09:54
197 查看
//自定义日期类型转化函数ChangeDateFormat,将//Date(1294499956278+0800)//形式的函数转化为2014-5-2形式
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;
}
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;
}
相关文章推荐
- 【前端】格式化Json传递的日期
- JSON Date Format (json的日期格式化)
- JS~json日期格式化
- ASP.NET WebApi 自带Json返回日期带T无法格式化的问题
- json格式的日期格式化
- JSON日期格式化
- springmvc 返回json数据日期格式化方法
- net.sf.json 日期 时间 格式化 方法
- java 实体类中日期属性格式化 @JSONFORMAT 日期格式自动格式化
- js解析格式化json日期
- 返回json数据,格式化日期类型去掉时分秒
- 关于json返回日期格式化的解决方案
- fastjson的日期格式化
- WebApi 返回小驼峰式 json 格式,并格式化日期
- springMVC4.2返回日期格式化的json串,同时解决中文乱码
- 【补】解决Sping MVC中,返回JSON日期格式化及时区问题
- json对象的用法包括日期格式化
- 用JS将json日期格式化成正常日期
- Spring3.1返回Json时格式化日期Date
- springMVC返回的json日期为Long的格式化