function dateFormat(time, fmStr) { const weekCN = '一二三四五六日' const weekEN = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] let year = time.getFullYear() let month = time.getMonth() + 1 let day = time.getDate() let hours = time.getHours() let minutes = time.getMinutes() let seconds = time.getSeconds() let milliSeconds = time.getMilliseconds() let week = time.getDay() month = month >= 10 ? month : '0' + month day = day >= 10 ? day : '0' + day hours = hours >= 10 ? hours : '0' + hours minutes = minutes >= 10 ? minutes : '0' + minutes seconds = seconds >= 10 ? seconds : '0' + seconds if (fmStr.indexOf('yyyy') !== -1) { fmStr = fmStr.replace('yyyy', year) } else { fmStr = fmStr.replace('yy', (year + '').slice(2)) } fmStr = fmStr.replace('MM', month) fmStr = fmStr.replace('dd', day) fmStr = fmStr.replace('HH', hours) fmStr = fmStr.replace('mm', minutes) fmStr = fmStr.replace('ss', seconds) fmStr = fmStr.replace('SSS', milliSeconds) fmStr = fmStr.replace('W', weekCN[week - 1]) fmStr = fmStr.replace('ww', weekEN[week - 1]) fmStr = fmStr.replace('w', week) return fmStr }
标签:格式化,函数,month,fmStr,replace,seconds,let,time,js From: https://www.cnblogs.com/zhuifeng-/p/17340874.html