封装好的日期函数
作者:互联网
1 function date(time) { 2 let date = new Date(time) 3 let year = date.getFullYear() 4 let month = date.getMonth() + 1 5 let day = date.getDate() 6 let week = date.getDay() 7 8 let hours = date.getHours() > 10 ? date.getHours() : '0' + date.getHours() 9 let mins = date.getMinutes() > 10 ? date.getMinutes() : '0' + date.getMinutes() 10 let s = date.getSeconds() > 10 ? date.getSeconds() : '0' + date.getSeconds() 11 let dateArr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'] 12 console.log(`${year}-${month}-${day} ${hours}:${mins}:${s} ${dateArr[week]}`); 13 14 }
标签:10,封装,函数,getSeconds,getHours,日期,let,date,getMinutes 来源: https://www.cnblogs.com/maxiaopi/p/16599609.html