Javatpoint Logo
Javatpoint Logo

Java LocalTime class

Java LocalTime class is an immutable class that represents time with a default format of hour-minute-second. It inherits Object class and implements the Comparable interface.


Java LocalTime class declaration

Let's see the declaration of java.time.LocalTime class.

Methods of Java LocalTime

Method Description
LocalDateTime atDate(LocalDate date) It is used to combine this time with a date to create a LocalDateTime.
int compareTo(LocalTime other) It is used to compare this time to another time.
String format(DateTimeFormatter formatter) It is used to format this time using the specified formatter.
int get(TemporalField field) It is used to get the value of the specified field from this time as an int.
LocalTime minusHours(long hoursToSubtract) It is used to return a copy of this LocalTime with the specified number of hours subtracted.
LocalTime minusMinutes(long minutesToSubtract) It is used to return a copy of this LocalTime with the specified number of minutes subtracted.
static LocalTime now() It is used to obtain the current time from the system clock in the default time-zone.
static LocalTime of(int hour, int minute, int second) It is used to obtain an instance of LocalTime from an hour, minute and second.
LocalTime plusHours(long hoursToAdd) It is used to return a copy of this LocalTime with the specified number of hours added.
LocalTime plusMinutes(long minutesToAdd) It is used to return a copy of this LocalTime with the specified number of minutes added.

Java LocalTime Example: now()

Test it Now

Output:

15:19:47.459

Java LocalTime Example: of()

Test it Now

Output:

10:43:12

Java LocalTime Example: minusHours() and minusMinutes()

Test it Now

Output:

10:43:12
08:09:12

Java LocalTime Example: plusHours() and plusMinutes()

Test it Now

Output:

10:43:12
15:01:12

Java LocalTime Example

Test it Now

Output:

India Time Zone: 14:56:43.087
Japan Time Zone: 18:26:43.103
Hours between two Time Zone: 3
Minutes between two time zone: 210
Next TopicJava LocalDateTime




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA