1export function formatDate(date, fmt) { 2 if (/(y+)/.test(fmt)) { 3 fmt = fmt.replace( 4 RegExp.$1, 5 (date.getFullYear() + '').substr(4 - RegExp.$1.length) 6 ); 7 } 8 const o = { 9 'M+': date.getMonth() + 1, 10 'd+': date.getDate(), 11 'h+': date.getHours(), 12 'm+': date.getMinutes(), 13 's+': date.getSeconds() 14 }; 15 for (const k in o) { 16 if (new RegExp(`(${k})`).test(fmt)) { 17 const str = o[k] + ''; 18 fmt = fmt.replace( 19 RegExp.$1, 20 RegExp.$1.length === 1 ? str : padLeftZero(str) 21 ); 22 } 23 } 24 return fmt; 25} 26formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss') // 2024-10-14 17:16:20
时间转换方法

达里尔
2024-10-23
1308 0 0
点赞
收藏
评论区
加载中...