1,写了一个time.js文件
//获取当前时间
export function DefaultDisplayLastMonth() {
//修改数据date
let currentTime = ''
currentTime = new Date().getFullYear() +
"-" +
(new Date().getMonth() + 1) +
"-" +
new Date().getDate() +
" " +
new Date().getHours() +
":" +
new Date().getMinutes() +
": " +
new Date().getSeconds();
let date = new Date(currentTime);
let date_value =
date.getFullYear() +
"-" +
(date.getMonth() + 1) +
"-" +
date.getDate();
currentTime = date_value
return currentTime
}
2,再需要用到time.js的文件里引入
import {
DefaultDisplayLastMonth
} from '@/api/time'
console.log(DefaultDisplayLastMonth())