public static String getTimeAgo ( final long time , final Locale locale ) { final BeanManager beanManager = BeanManager . getInstance ( ) ; final LangPropsService langService = beanManager . getReference ( LangPropsService . class ) ; final Map < String , String > langs = langService . getAll ( locale ) ; final long diff = System . currentTimeMillis ( ) - time ; long r ; if ( diff > YEAR_UNIT ) { r = diff / YEAR_UNIT ; return r + " " + langs . get ( "yearsAgoLabel" ) ; } if ( diff > MONTH_UNIT ) { r = diff / MONTH_UNIT ; return r + " " + langs . get ( "monthsAgoLabel" ) ; } if ( diff > WEEK_UNIT ) { r = diff / WEEK_UNIT ; return r + " " + langs . get ( "weeksAgoLabel" ) ; } if ( diff > DAY_UNIT ) { r = diff / DAY_UNIT ; return r + " " + langs . get ( "daysAgoLabel" ) ; } if ( diff > HOUR_UNIT ) { r = diff / HOUR_UNIT ; return r + " " + langs . get ( "hoursAgoLabel" ) ; } if ( diff > MINUTE_UNIT ) { r = diff / MINUTE_UNIT ; return r + " " + langs . get ( "minutesAgoLabel" ) ; } return langs . get ( "justNowLabel" ) ; }
Gets time ago format text .