export class DateFormat { param date param format return author adswads gmail public static format ( date ? , format ? ) { if ( date == undefined && format == undefined ) { date = new Date ( ) ; format = "yyyy-MM-dd HH:mm:ss" ; } else if ( typeof date == "string" ) { format = date ; date = new Date ( ) ; } else if ( format === undefined ) { format = "yyyy-MM-dd HH:mm:ss" ; } else { } var map = { y : date . getFullYear ( ) + "" , M : date . getMonth ( ) + 1 + "" , d : date . getDate ( ) + "" , H : date . getHours ( ) , m : date . getMinutes ( ) + "" , s : date . getSeconds ( ) + "" , q : Math . floor ( ( date . getMonth ( ) + 3 ) / 3 ) + "" , f : date . getMilliseconds ( ) + "" , } ; if ( map [ "H" ] > 12 ) { map [ "h" ] = map [ "H" ] - 12 + "" ; } else { map [ "h" ] = map [ "H" ] + "" ; } map [ "H" ] += "" ; var reg = "yMdHhmsqf" ; var all = "" , str = "" ; for ( var i = 0 , n = 0 ; i < reg . length ; i ++ ) { n = format . indexOf ( reg [ i ] ) ; if ( n < 0 ) { continue ; } all = "" ; for ( ; n < format . length ; n ++ ) { if ( format [ n ] != reg [ i ] ) { break ; } all += reg [ i ] ; } if ( all . length > 0 ) { if ( all . length == map [ reg [ i ] ] . length ) { str = map [ reg [ i ] ] ; } else if ( all . length > map [ reg [ i ] ] . length ) { if ( reg [ i ] == "f" ) { str = map [ reg [ i ] ] + this . charString ( "0" , all . length - map [ reg [ i ] ] . length ) ; } else { str = this . charString ( "0" , all . length - map [ reg [ i ] ] . length ) + map [ reg [ i ] ] ; } } else { switch ( reg [ i ] ) { case "y" : str = map [ reg [ i ] ] . substr ( map [ reg [ i ] ] . length - all . length ) ; break ; case "f" : str = map [ reg [ i ] ] . substr ( 0 , all . length ) ; break ; default : str = map [ reg [ i ] ] ; break ; } } format = format . replace ( all , str ) ; } } return format ; } param char param count return author adswads gmail private static charString ( char , count ) { var str = "" ; while ( count -- ) { str += char ; } return str ; } }