函数的形式
getDate() {
let currentDate = new Date();
let year = currentDate.getFullYear();
let month = currentDate.getMonth() + 1;
let day = currentDate.getDate();
month = month < 10 ? '0' + month : month;
day = day < 10 ? '0' + day : day;
},
引入的方式,此处可以根据自己的需求来返回时间的形式
export function getTime() {
var now = new Date();
var year = now.getFullYear();
var month = (now.getMonth() + 1).toString();
var day = (now.getDate()).toString();
var hour = (now.getHours()).toString();
var minute = (now.getMinutes()).toString();
var second = (now.getSeconds()).toString();
if (month.length == 1) {
month = "0" + month;
}
if (day.length == 1) {
day = "0" + day;
}
if (hour.length == 1) {
hour = "0" + hour;
}
if (minute.length == 1) {
minute = "0" + minute;
}
if (second.length == 1) {
second = "0" + second;
}
var dateTime = year+"-" +month+ "-" + day;
return dateTime;
}
-- 别的页面调用 import {getTime} from '../../../libs/util/gteTime.js'