格式化Json傳遞的日期


自定義日期類型轉化函數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           }  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM