You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
833 B

export default {
formatDate(timestamp){
// 获取当前时间戳(单位:毫秒)
// var timestamp = Date.now(); // 或者传入特定的时间戳值
timestamp = timestamp ? timestamp :Date.now()
// 创建Date对象并设置时间戳
var dateObj = new Date(timestamp);
// 提取年份、月份、日期等信息
var year = dateObj.getFullYear();
var month = (dateObj.getMonth() + 1).toString().padStart(2, '0'); // 注意月份从0开始计数,所以需要加1
var day = dateObj.getDate().toString().padStart(2, '0');
var hour = dateObj.getHours().toString().padStart(2, '0');
var minutes = dateObj.getMinutes().toString().padStart(2, '0');
var seconds = dateObj.getSeconds().toString().padStart(2, '0');
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`
}
}