記錄開發過程中的代碼片段,方便日后歸納、總結,效果如圖所示:
轉換前:
轉換后:
代碼如下,需要的朋友們自取:
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 }