JS中将字符串的中国标准时间格式化

tech2026-10-05  3

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(' '); }

将字符串传入即可

最新回复(0)