import { replace } from '../string/index' ; obj desc method const date = { func desc param { string } format return { function } createFormatDate : function ( format = 'YYYY/MM/DD hh:mm' ) : ( ms : number ) => string { let replaceFormat = replace ( /[a-zA-Z]+/g ) ; return ( ms ) : string => { const dateFunctions = { 'Y' : 'getFullYear' , 'M' : 'getMonth' , 'D' : 'getDate' , 'h' : 'getHours' , 'm' : 'getMinutes' , 's' : 'getSeconds' , 'w' : 'getDay' , 'W' : 'getDay' } ; const weeks = { 'w' : [ 'Sun.' , 'Mon.' , 'Tues.' , 'Wed.' , 'Thur.' , 'Fri.' , 'Sat.' ] , 'W' : [ '日' , '一' , '二' , '三' , '四' , '五' , '六' ] . map ( week => `星期${ week }` ) } ; let date = new Date ( ms ) ; return replaceFormat ( format , ( matchStr ) : string => { let dateFuncName = dateFunctions [ matchStr [ 0 ] ] ; if ( dateFuncName ) { if ( dateFuncName === 'getMonth' ) { const str = `0000${ date [ dateFuncName ] ( ) + 1 }` ; return str . substring ( str . length - matchStr . length ) ; } else if ( dateFuncName === 'getDay' ) { return weeks [ matchStr [ 0 ] ] [ date [ dateFuncName ] ( ) ] ; } else { const str = '0000' + date [ dateFuncName ] ( ) ; return str . substring ( str . length - matchStr . length ) ; } } else { return matchStr ; } } ) ; } ; } } ; export default date ; export const createFormatDate = date . createFormatDate ;