// 日期数据 格式化 (公共函数)+ 数字补0操作
function addZero(num) {
return num < 10 ? '0' + num : num;
}
function formatDateTime(date) {
const time = new Date(Date.parse(date));
time.setTime(time.setHours(time.getHours() + 8));
const Y = time.getFullYear() + '-';
const M = addZero(time.getMonth() + 1) + '-';
const D = addZero(time.getDate()) + ' ';
const h = addZero(time.getHours()) + ':';
const m = addZero(time.getMinutes()) + ':';
const s = addZero(time.getSeconds());
return Y + M + D + h + m + s;
}
export {
formatDateTime
};
時間格式轉換
最新推荐文章于 2024-10-07 09:24:46 发布