constformatTime= date =>{var date =newDate()//一定要记得写这个,不然会报date.getFullYear is not a functionconst year = date.getFullYear()const month = date.getMonth()+1const day = date.getDate()const hour = date.getHours()const minute = date.getMinutes()const second = date.getSeconds()return[year, month, day].map(formatNumber).join('/')+' '+[hour, minute, second].map(formatNumber).join(':')}constformatNumber= n =>{
n = n.toString()return n[1]? n :'0'+ n
}
module.exports ={
formatTime: formatTime,}
2.导入
const time =require("../../utils/util.js");//根据自己项目的位置而定
3.使用
var currenttime= res.data.timeStamp;
console.log(time.formatTime(currenttime,'Y/M/D h:m:s'));
4.注意了喔 date.getFullYear is not a function 是因为util.js中没有写下面一行代码