Json序列化日期/Date(xxxx)/ JS轉化為常用日期格式


記錄開發過程中的代碼片段,方便日后歸納、總結,效果如圖所示:

轉換前:   

轉換后:

 

代碼如下,需要的朋友們自取:

 1 //JS轉化為json常用日期格式
 2         function FormatToDate(val) {
 3             if (val != null) {
 4                 var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
 5                 //月份為0-11,所以+1,月份小於10時補個0
 6                 var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
 7                 var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
 8                 return date.getFullYear() + "-" + month + "-" + currentDate;
 9             }
10             return "";
11         }

 

 

 


免責聲明!

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



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