输入banner图图片脚本导航/分类

格式化Json传递日期的方法

自定义日期类型转化函数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;
          }

以上就是格式化Json传递日期的方法的详细内容,更多请关注Gxl网其它相关文章!