export function formattedDateTime(timestamp) {
// const timestamp = 1688396840000; // 时间戳
const date = new Date(timestamp); // 创建 Date 对象
const year = date.getFullYear(); // 获取年份
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份,并补零
const day = date.getDate().toString().padStart(2, '0'); // 获取日期,并补零
const hours = date.getHours().toString().padStart(2, '0'); // 获取小时,并补零
const minutes = date.getMinutes().toString().padStart(2, '0'); // 获取分钟,并补零
const seconds = date.getSeconds().toString().padStart(2, '0'); // 获取秒数,并补零
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 格式化日期和时间字符串
}
根据提供的时间戳 1688396840000,可以将其转换为年月日时分秒的形式。
猜你喜欢
转载自blog.csdn.net/qq_44716001/article/details/131517014
今日推荐
周排行