函数
1 function fmtDate(obj){ 2 var date = new Date(obj); 3 var y = 1900+date.getYear(); 4 var m = "0"+(date.getMonth()+1); 5 var d = "0"+date.getDate(); 6 return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length); 7 }
JS中调用
1 fmtDate(data);
显示格式:2018-07-08