public String format ( Calendar calendar , Calendar smscCalendar ) { if ( calendar == null || smscCalendar == null ) { return null ; } long diffTimeInMillis = calendar . getTimeInMillis ( ) - smscCalendar . getTimeInMillis ( ) ; if ( diffTimeInMillis < 0 ) { throw new IllegalArgumentException ( "The requested relative time has already past." ) ; } // calculate period from epoch, this is not as accurate as Joda-Time Period class or Java 8 Period Calendar offsetEpoch = Calendar . getInstance ( utcTimeZone ) ; offsetEpoch . setTimeInMillis ( diffTimeInMillis ) ; int years = offsetEpoch . get ( Calendar . YEAR ) - 1970 ; int months = offsetEpoch . get ( Calendar . MONTH ) ; int days = offsetEpoch . get ( Calendar . DAY_OF_MONTH ) - 1 ; int hours = offsetEpoch . get ( Calendar . HOUR_OF_DAY ) ; int minutes = offsetEpoch . get ( Calendar . MINUTE ) ; int seconds = offsetEpoch . get ( Calendar . SECOND ) ; if ( years >= 100 ) { throw new IllegalArgumentException ( "The requested relative time is more then a century (" + years + " years)." ) ; } return format ( years , months , days , hours , minutes , seconds ) ; }
Return the relative time from the calendar datetime against the SMSC datetime .