首页 > Web开发 > 详细

格式化Json传递的日期

时间:2017-10-15 20:39:01      阅读:241      评论:0      收藏:0      [点我收藏+]

自定义日期类型转化函数ChangeDateFormat,将//Date(1294499956278+0800)//形式的函数转化为2014-5-2形式

 1  function ChangeDateFormat(jsondate) {
 2               jsondate = jsondate.replace("/Date(", "").replace(")/", "");
 3               if (jsondate.indexOf("+") > 0) {
 4                   jsondate = jsondate.substring(0, jsondate.indexOf("+"));
 5               } else if (jsondate.indexOf("-") > 0) {
 6                   jsondate = jsondate.substring(0, jsondate.indexOf("-"));
 7               }
 8               var date = new Date(parseInt(jsondate, 10));
 9               var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
10               var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
11               return date.getFullYear() + "-" + month + "-" + currentDate;
12           }  

 

格式化Json传递的日期

原文:http://www.cnblogs.com/senfanxie/p/7672966.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!