public static String naturalDay ( int style , Date then ) { Date today = new Date ( ) ; long delta = then . getTime ( ) - today . getTime ( ) ; long days = delta / ND_FACTOR ; if ( days == 0 ) return context . get ( ) . getMessage ( "today" ) ; else if ( days == 1 ) return context . get ( ) . getMessage ( "tomorrow" ) ; else if ( days == - 1 ) return context . get ( ) . getMessage ( "yesterday" ) ; return formatDate ( style , then ) ; }
For dates that are the current day or within one day return today tomorrow or yesterday as appropriate . Otherwise returns a string formatted according to a locale sensitive DateFormat .