public static Duration fromMillis ( long milliseconds ) { Duration . Builder builder = builder ( ) ; if ( milliseconds < 0 ) { builder . prior ( true ) ; milliseconds *= - 1 ; } int seconds = ( int ) ( milliseconds / 1000 ) ; Integer weeks = seconds / ( 60 * 60 * 24 * 7 ) ; if ( weeks > 0 ) { builder . weeks ( weeks ) ; } seconds %= 60 * 60 * 24 * 7 ; Integer days = seconds / ( 60 * 60 * 24 ) ; if ( days > 0 ) { builder . days ( days ) ; } seconds %= 60 * 60 * 24 ; Integer hours = seconds / ( 60 * 60 ) ; if ( hours > 0 ) { builder . hours ( hours ) ; } seconds %= 60 * 60 ; Integer minutes = seconds / ( 60 ) ; if ( minutes > 0 ) { builder . minutes ( minutes ) ; } seconds %= 60 ; if ( seconds > 0 ) { builder . seconds ( seconds ) ; } return builder . build ( ) ; }
Builds a duration from a number of milliseconds .