function formatDate(date, format) { if (!format) format = 'YYYY/MM/DD hh:mm:ss'; format = format.replace(/YYYY/g, date.getFullYear()); format = format.replace(/MM/g, ('0' + (date.getMonth() + 1)).slice(-2)); format = format.replace(/DD/g, ('0' + date.getDate()).slice(-2)); format = format.replace(/hh/g, ('0' + date.getHours()).slice(-2)); format = format.replace(/mm/g, ('0' + date.getMinutes()).slice(-2)); format = format.replace(/ss/g, ('0' + date.getSeconds()).slice(-2)); format = format.replace(/M/g, date.getMonth() + 1); format = format.replace(/D/g, date.getDate()); format = format.replace(/h/g, date.getHours()); return format; }
js格式化时间
最新推荐文章于 2024-09-11 15:33:18 发布