js 时间戳转换为自己想要的时间格式

function localData(value) {

let date = new Date(value );

let Month = date.getMonth() + 1;

let Day = date.getDate();

let Y = date.getFullYear() + '-';

let M = Month < 10 ? '0' + Month + '-' : Month + '-';

let D = Day + 1 < 10 ? '0' + Day : Day;

return Y + M + D;

}

console.log(localData('123456787'))

 

你可能感兴趣的:(js基本知识)