函数如下:

function fmtDate(obj){
         obj = (typeof(obj) == "number") ? obj : Number(obj);
         var date =  new Date(obj);
         var y = 1900+date.getYear();
         var m = "0"+(date.getMonth()+1);
         var d = "0"+date.getDate();
         return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
}

test:

fmtDate(1520438400000);

输出:

"2018-03-08"