Intro
suggest changeLocalTime is an immutable, thread-safe class used to represent a time of day, often viewed as hour-minute-second. Time is represented to nanosecond precision. For example, the value “13:45:30.123456789” can be stored in a LocalTime.
This class does not store or represent a date or time-zone. Instead, it is a description of the local time as seen on a wall clock. It cannot represent an instant on the time-line without additional information such as an offset or time-zone. This is a value-based class; compare instances with equals, not with ==.
Fields
MAX is the maximum supported LocalTime, 23:59:59.999999999. MIN and MIDNIGHT are both 00:00. NOON is 12:00.
Important Static Methods
now(), now(Clock clock), now(ZoneId zone), parse(CharSequence text)
Important Instance Methods
isAfter(LocalTime other), isBefore(LocalTime other), minus(TemporalAmount amountToSubtract), minus(long amountToSubtract, TemporalUnit unit), plus(TemporalAmount amountToAdd), plus(long amountToAdd, TemporalUnit unit)
ZoneId zone = ZoneId.of("Asia/Kolkata");
LocalTime now = LocalTime.now();
LocalTime now1 = LocalTime.now(zone);
LocalTime then = LocalTime.parse("04:16:40");
The difference between two wall-clock times can be calculated in either of these ways. now and now1 are local times in different zones, so the result is not an elapsed duration on the timeline.
long timeDiff = Duration.between(now, now1).toMinutes();
long timeDiff1 = java.time.temporal.ChronoUnit.MINUTES.between(now, now1);
You can also add or subtract hours, minutes, or seconds. These methods return a new LocalTime; they do not change the original.
minusHours(long hoursToSubtract), minusMinutes(long minutesToSubtract), minusNanos(long nanosToSubtract), minusSeconds(long secondsToSubtract), plusHours(long hoursToAdd), plusMinutes(long minutesToAdd), plusNanos(long nanosToAdd), plusSeconds(long secondsToAdd)
now.plusHours(1L);
now1.minusMinutes(20L);