ISO 8601 Duration
As mentioned in the answer by Crissov, the ISO 8601 standard defines a textual representation of a span of time in this format: PnYnMnDTnHnMnS
, called Durations.
In this format, the P
marks the beginning. The T
separates the days portion from the time (fractional day) portion, and is omitted for whole days.
Examples:
P1D
= One whole day.
PT5M
= 5 minutes.
PT4H30M
means "four and a half hours".
P3Y6M4DT12H30M5S
represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds".
Even Briefer: 4H 30M
You could truncate the PT
for presentation to the user. So four and a half hours would be: 4H30M
.
Perhaps add a space for readability: 4H 30M
.
Pros
The upside is that this format is unambiguous, and won't be confused for some other meaning. Another benefit is the fact it is a standard. And the values are somewhat intuitive and easy to read and understand.
Cons
One downside is that users may not be familiar. So a moment of explanation or training may be needed.
Programming
Some programming libraries can parse and generate such strings. For Java, the Joda-Time library does so handily with its Period
class. Similarly, the new java.time package built into Java 8 also offers a Period
class.
Example using Joda-Time 2.7.
DateTime now = DateTime.now();
Period period = new Period( now , now.plusHours( 7 ) );
System.out.println( "period: " + period.toString() );
Output:
period: PT7H