Local Time in Java

A LocatTime represents a time of day, such as 15:30:00. You can create an instance with the now or of methods:

LocalTime rightNow = LocalTime.now();

LocalTime bedtime = LocalTime.of(22, 30); // or LocatTime.of(22, 30, 0)

The API notes show common operations with local times. The plus and minus operations wrap around a 24-hour day. For example,

LocalTime wakeup = bedtime.plusHoursiS); // wakeup is 6:30:00

There is a LocalDateTime class representing a date and time. That class is suitable for storing points in time in a fixed time zone—for example, for a schedule of classes or events. However, if you need to make calculations that span the daylight savings time, or if you need to deal with users in different time zones, you should use the ZonedDateTime class that we discuss next.

Source: Horstmann Cay S. (2019), Core Java. Volume II – Advanced Features, Pearson; 11th edition.

Leave a Reply

Your email address will not be published. Required fields are marked *