java.time
Use the java.time class classes that were found bundled with Java 8 and later and migrated back to earlier versions.
Duration
To represent a time span with granularity of seconds-minutes-hours-days, use Duration .
Period
To represent a time span with granularity of days-months-years, use Period .
ISO 8601
Also study the standard ISO 8601 formats for strings representing date and time values.
For time periods, the standard uses the format PnYnMnDTnHnMnS , where P marks the beginning and T separates any years-months-days from any hours-minutes-seconds. So, an hour and a half - PT1H30M .
The java.time classes use the standard ISO 8601 formats by default when parsing and generating strings.
String output = duration.toString();
PT1H30M
Duration duration = Duration.parse( "PT1H30M" );
ThreeTen-Extra
See the ThreeTen-Extra project for more classes such as Interval , the plurality of Days and Weeks and Months and Years , quarters and standard ISO 8601 weeks .
source share