let timeStamp =newDate().getTime()// 1574672217484//timeStamp 传入的时间戳functiongetDate(timeStamp){let time =newDate(timeStamp)// Mon Nov 25 2019 16:56:57 GMT+0800 (中国标准时间)let year = time.getFullYear()let month =getHandledValue(time.getMonth()+1)let date =getHandledValue(time.getDate())let hours =getHandledValue(time.getHours())let minutes =getHandledValue(time.getMinutes())let second =getHandledValue(time.getSeconds())let resStr =''
resStr = year +'-'+ month +'-'+ date +' '+ hours +':'+ minutes +':'+ second
return resStr
}// 将个位数转化为两位数显示functiongetHandledValue(num){return num <10?'0'+ num : num
}
console.log(getDate(timeStamp))// 2019-11-25 16:56:57
获得当前时间的时间戳 let time = new Date() // .getTime() 精确到毫秒 let timeStamp = time.getTime(); console.log(timeStamp); // 1574671049842 // .valueOf() 精确到毫秒 let timeStamp1 = time.valueOf(...