TL; DR
zdt.with ( LocalTime.of ( 16 , 15 ) )
Immutable objects
The java.time classes use the Immutable Objects template to create new objects and not modify ("mutate") the original object.
with()
A method ZonedDateTime::withis a flexible way of generating a new one ZonedDateTimeon the basis of another, but with a certain difference. You can pass any object that implements the interface TemporalAdjustor.
. LocalTime - - . LocalTime TemporalAdjustor. , .
ZonedDateTime marketOpens = ZonedDateTime.of ( LocalDate.of ( 2016 , 1 , 4 ) , LocalTime.of ( 9 , 30 ) , ZoneId.of ( "America/New_York" ) );
ZonedDateTime marketCloses = marketOpens.with ( LocalTime.of ( 16 , 0 ) );
, , .
Duration duration = Duration.between ( marketOpens , marketCloses );
.
System.out.println ( "marketOpens: " + marketOpens + " | marketCloses: " + marketCloses + " | duration: " + duration );
marketOpens: 2016-01-04T09: 30-05: 00 [America/New_York] | marketCloses: 2016-01-04T16: 00-05: 00 [America/New_York] | : PT6H30M
, . LocalTime , , . . 0 LocalTime. LocalTime ZonedDateTime.
TemporalAdjustor. . , LocalDate, Month, Year . , , .
Hochschild. , , . , (DST).