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 Class
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()
LocalTimeExample1.java
Test it Now
Output:
Java LocalTime Example: of()
LocalTimeExample2.java
Test it Now
Output:
Java LocalTime Example: minusHours() and minusMinutes()
LocalTimeExample3.java
Test it Now
Output:
Java LocalTime Example: plusHours() and plusMinutes()
LocalTimeExample4.java
Test it Now
Output:
Java LocalTime Example
LocalTimeExample5.java
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
|