TL;DR
Duration.between(
Instant.parse( "2010-03-15T16:34:46Z" ) ,
Instant.now()
)
.toHoursPart()
+ " hours ago"
5
java.time
java.time, .
Instant
. , ISO 8601. java.time / . .
Instant instant = Instant.parse( "2010-03-15T16:34:46Z" ) ;
.
Instant later = instant.now() ;
.
Instant later = instant.plus( 5L , ChronoUnit.HOURS ) ;
Duration
-- Duration.
Duration d = Duration.between( instant , later ) ;
Java 9 toβ¦Part, , , , , . Java 8, Java 9 .
String output = d.toHoursPart() + " hours ago" ;
5
ISO 8601
, ISO 8601, , Duration::toString: PnYnMnDTnHnMnS
P . T -- --.
, :
PT5H
Duration .
Duration d = Duration.parse( "PT5H" ) ;