function formatDateTime (newDate) {
newDate =new Date(newDate);
let Month = newDate.getMonth() + 1;
Month = Month >= 10 ? Month : '0' + Month;
let d = newDate.getDate();
d = d >= 10 ? d : '0' + d
return [
[newDate.getFullYear(), Month, d].join('-'), [newDate.getHours(), newDate.getMinutes(), newDate.getSeconds()].join(':')
].join(' ');
}
将字符串传入即可

本文介绍了一个用于格式化日期和时间的JavaScript函数。该函数接收一个日期字符串作为输入,返回一个格式化的日期时间字符串,包括年、月、日、时、分、秒,适用于多种应用场景。
5679

被折叠的 条评论
为什么被折叠?



