32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
|
|
|
|
export default {
|
|
getDate() {
|
|
const currentDate = new Date();
|
|
|
|
const year = currentDate.getFullYear().toString();
|
|
const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份是从 0 开始计数的,所以要加 1
|
|
const day = currentDate.getDate().toString().padStart(2, '0');
|
|
|
|
const formattedDate = `${year}-${month}-${day}`;
|
|
|
|
return formattedDate;
|
|
},
|
|
|
|
getDateTime() {
|
|
const currentDate = new Date();
|
|
|
|
const year = currentDate.getFullYear().toString();
|
|
const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份是从 0 开始计数的,所以要加 1
|
|
const day = currentDate.getDate().toString().padStart(2, '0');
|
|
const hours = currentDate.getHours().toString().padStart(2, '0');
|
|
const minutes = currentDate.getMinutes().toString().padStart(2, '0');
|
|
const seconds = currentDate.getSeconds().toString().padStart(2, '0');
|
|
|
|
const formattedTime = `${hours}:${minutes}:${seconds}`;
|
|
|
|
const formattedDateTime = `${year}${month}${day} ${formattedTime}`;
|
|
|
|
return formattedDateTime;
|
|
}
|
|
} |