![]() |
VOOZH | about |
Java is the most popular programming language and widely used programming language. Java is used in all kinds of applications like mobile applications, desktop applications, web applications. As in Java, java.time.LocalTime class represents time, which is viewed as hour-minute-second. This class is immutable and also thread-safe. There are various methods under java.time.LocalTime class which is explained below and implementation is also performed below. java.time is a package used to work with the current date and time API.
First most all the methods of this class is demonstrated below in tabular format as shown:
| Method | Description |
|---|---|
| adjustInto(Temporal temporal) |
All MethodsStatic MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description Temporal |
| atDate(LocalDate date) | Combines this time with a date to create a LocalDateTime. |
| atOffset(ZoneOffset offset) | Combines this time with an offset to create an OffsetTime. |
| compareTo(LocalTime other) | Compares this time to another time. |
| equals(Object obj) | Checks if this time is equal to another time. |
| format(DateTimeFormatter formatter) | Formats this time using the specified formatter. |
| get(TemporalField field) | Gets the value of the specified field from this time as an int. |
| getHour() | Gets the hour-of-day field. |
| getMinute() | Gets the minute-of-hour field. |
| getNano() | Gets the nano-of-second field. |
| getSecond() | Gets the second-of-minute field. |
| hashCode() | A hash code for this time. |
| isAfter(LocalTime other) | Checks if this time is after the specified time. |
| isBefore(LocalTime other) | Checks if this time is before the specified time. |
| isSupported(TemporalField field) | Checks if the specified field is supported. |
| minus(long amountToSubtract, TemporalUnit unit) | Returns a copy of this time with the specified amount subtracted. |
| minusHours(long hoursToSubtract) | Returns a copy of this LocalTime with the specified number of hours subtracted. |
| minusMinutes(long minutesToSubtract) | Returns a copy of this LocalTime with the specified number of minutes subtracted. |
| minusNanos(long nanosToSubtract) | Returns a copy of this LocalTime with the specified number of nanoseconds subtracted. |
| minusSeconds(long secondsToSubtract) | Returns a copy of this LocalTime with the specified number of seconds subtracted. |
| now() | Obtains the current time from the system clock in the default time-zone. |
| of(int hour, int minute) | Obtains an instance of LocalTime from an hour and minute. |
| ofNanoOfDay(long nanoOfDay) | Obtains an instance of LocalTime from a nanos-of-day value. |
| ofSecondOfDay(long secondOfDay) | Obtains an instance of LocalTime from a second-of-day value. |
| parse(CharSequence text) | Obtains an instance of LocalTime from a text string such as 10:15. |
| plus(TemporalAmount amountToAdd) | Returns a copy of this time with the specified amount added. |
| plusHours(long hoursToAdd) | Returns a copy of this LocalTime with the specified number of hours added. |
| plusMinutes(long minutesToAdd) | Returns a copy of this LocalTime with the specified number of minutes added. |
| plusNanos(long nanosToAdd) | Returns a copy of this LocalTime with the specified number of nanoseconds added. |
| plusSeconds(long secondstoAdd) | Returns a copy of this LocalTime with the specified number of seconds added. |
| query(TemporalQuery<R> query) | Queries this time using the specified query. |
| range(TemporalField field) | Gets the range of valid values for the specified field. |
| toNanoOfDay() | Extracts the time as nanos of day, from 0 to 24 * 60 * 60 * 1,000,000,000 - 1. |
| truncatedTo(TemporalUnit unit) | Returns a copy of this LocalTime with the time truncated. |
| with(TemporalAdjuster adjuster) | Returns an adjusted copy of this time. |
| withHour(int hour) | Returns a copy of this LocalTime with the hour-of-day altered. |
| withMinute(int minute) | Returns a copy of this LocalTime with the minute-of-hour altered. |
| withNano(int nanoOfSecond) | Returns a copy of this LocalTime with the nano-of-second altered. |
| withSecond(int second) | Returns a copy of this LocalTime with the second-of-minute altered. |
Implementation:
Example 1
Local time value : 06:20:52.986897
Example 2
Time : 08:34:59.135137
Example 3
17:48:53.003478
Example 4
10:54:49.649675