padStart()从前面开始补充,padEnd()从后面开始补充
举个例子:
实例: let name = ‘12’
name.padStart(5,'abc') //abc12
name.padStart(7,'abc') //abcab12
上干货:
let date = new Date()
let year = date.getFullYear()
let month = (date.getMonth()+1).toString().padStart(2,'0')
let day = date.getDate().toString().padStart(2,'0')
var time = year+'-'+month+'-'+day
console.log(time) // 2021-03-04
简单实用, 继续努力.