//有时分秒
getCurrentDate() {
let date = new Date(); //获取系统当前时间
let year = date.getFullYear(); //获取完整的年份(4位,1970-????)
let month =
Number(date.getMonth()) + 1 < 10
? `0${date.getMonth() + 1}`
: date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
let day =
Number(date.getDate()) < 10 ? `0${date.getDate()}` : date.getDate(); //获取当前日(1-31)
let hours = date.getHours(); //获取当前小时数(0-23)
let minutes = date.getMinutes(); //获取当前分钟数(0-59)
let second = date.getSeconds(); //获取当前秒数(0-59)
return `${year}-${month}-${day} ${hours}:${minutes}:${second}`;
}
//没有时分秒
getCurrentDate() {
let date = new Date(); //获取系统当前时间
let year = date.getFullYear(); //获取完整的年份(4位,1970-????)
let month =
Number(date.getMonth()) + 1 < 10
? `0${date.getMonth() + 1}`
: date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
let day =
Number(date.getDate()) < 10 ? `0${date.getDate()}` : date.getDate(); //获取当前日(1-31)
return `${year}-${month}-${day}`;
},
网友评论