Duration.between( zdtA , zdtB ) // Represent a span-of-time in terms of days (24-hour chunks of time, not calendar days), hours, minutes, seconds. Internally, a count of whole seconds plus a fractional second (nanoseconds).
For years, months, days:
Period.between( // Represent a span-of-time in terms of years-months-days.
zdtA.toLocalDate() , // Extract the date-only from the date-time-zone object.
zdtB.toLocalDate()
)
Another route is the Duration and Period classes. Use the first for shorter spans of time (hours, minutes, seconds), the second for longer (years, months, days).
Duration d = Duration.between( zdtA , zdtB );
Produce a String in standard ISO 8601 format by calling toString. The format is PnYnMnDTnHnMnS where the P marks the beginning and T separates the two portions.
String output = d.toString();
In Java 9 and later, call the to…Part methods to get the individual components. Discussed in another Answer of mine.
Example code
ZoneId z = ZoneId.of( "America/Montreal" );
ZonedDateTime zdtStart = ZonedDateTime.now( z );
ZonedDateTime zdtStop = zdtStart.plusHours( 3 ).plusMinutes( 7 );
Duration d = Duration.between( zdtStart , zdtStop );
The ThreeTen-Extra project adds functionality to the java.time classes. One of its handy classes is Interval to represent a span of time as a pair of points on the timeline. Another is LocalDateRange, for a pair of LocalDate objects. In contrast, the Period & Duration classes each represent a span of time as not attached to the timeline.
The factory method for Interval takes a pair of Instant objects.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes.
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.