将日期对象格式化封装在timeFormat方法中。
let timestamp=Date.parse(new Date);
let date=timeFormat(new Date(timestamp));
function timeFormat(date) {
let year=date.getFullYear()
let month=(date.getMonth()+1).toString().length<2?'0'+(date.getMonth()+1):(date.getMonth()+1);
let day=date.getDate().toString().length<2?'0'+date.getDate():date.getDate();
return year+'-'+month+'-'+day;
}