获取当前年月日
+new Date() 等于 new Date().getTime() 等于 Date.parse(new Date())
getCurrTime() {
const date = new Date();
let time = {
year: date.getFullYear(), //年
month: date.getMonth() + 1, // 月
day: date.getDate(), // 日
hours: date.getHours(), // 时
minutes: date.getMinutes(), // 分
seconds: date.getSeconds() // 秒
};
// time.month = (time.month < 10) ? ('0'+ time.month) : time.month
if (time.month < 10) {
time.month = '0' + time.month;
}
if (time.day < 10) {
time.day = '0' + time.day;
}
if (time.hours < 10) {
time.hours = '0' + time.hours;
}
if (time.minutes < 10) {
time.minutes = '0' + time.minutes;
}
if (time.seconds < 10) {
time.seconds = '0' + time.seconds;
}
const currTime = time.year + '-' + time.month + '-' + time.day + ' ' + time.hours + ':' + time.minutes + ':' + time.seconds;
}