@ Override public String asString ( Object object ) { // at this point object is a Date Calendar calendar = Calendar . getInstance ( TimeZone . getTimeZone ( "GMT" ) ) ; calendar . setTime ( ( Date ) object ) ; StringBuilder builder = new StringBuilder ( ) ; int year = calendar . get ( Calendar . YEAR ) ; if ( calendar . get ( Calendar . ERA ) == 0 ) { // https://en.wikipedia.org/wiki/ISO_8601 // by convention 1 BC is labeled +0000, 2 BC is labeled −0001, ... if ( year > 1 ) { builder . append ( ' ' ) ; } -- year ; } builder . append ( String . format ( "%04d" , year ) ) ; builder . append ( ' ' ) ; builder . append ( String . format ( "%02d" , calendar . get ( Calendar . MONTH ) + 1 ) ) ; builder . append ( ' ' ) ; builder . append ( String . format ( "%02d" , calendar . get ( Calendar . DATE ) ) ) ; builder . append ( ' ' ) ; builder . append ( String . format ( "%02d" , calendar . get ( Calendar . HOUR_OF_DAY ) ) ) ; builder . append ( ' ' ) ; builder . append ( String . format ( "%02d" , calendar . get ( Calendar . MINUTE ) ) ) ; builder . append ( ' ' ) ; builder . append ( String . format ( "%02d" , calendar . get ( Calendar . SECOND ) ) ) ; builder . append ( ' ' ) ; return builder . toString ( ) ; }
Return ISO8601 string representation for given date instance .