var timeDate = new Date()
//将时间的格式转化成20180101或者可以是2018-01-08
function transfer1() {
let timeDate = new Date()
let year = timeDate.getFullYear()
let temp1 = timeDate.getMonth() + 1
let month = temp1 < 10 ? '0' + temp1 : temp1
let temp2 = timeDate.getDate()
let day = temp2 < 10 ? '0' + temp2 : temp2
return year + month + day
}
//将时间转化成2018-01-02
function transfer2() {
let timeDate = transfer1() //等于的是20180108
if (!timeDate) return ''
// substring(开始位置,结束位置-1) ,substr(开始位置,字符串总的长度)
// jion()将数组转化成字符串,//split()将字符串转化成数组,分割,将字符串践行分割。
return [
timeDate.substring(0, 4),
timeDate.substring(4, 6),
timeDate.substring(6)
].join('-')
}