The java.time.LocalTime class represents a time without a time-zone in the ISO-8601 calendar system, such as 10:15:30.
Following is the declaration for java.time.LocalTime class −
public final class LocalTime extends Object implements Temporal, TemporalAdjuster, Comparable<LocalDate>, Serializable
Following are the fields for java.time.LocalTime class −
static LocalTime MAX − The maximum supported LocalTime, '23:59:59.999999999'.
static LocalTime MIN − The minimum supported LocalTime, '00:00'.
static LocalTime MIDNIGHT − The time of midnight at the start of the day, '00:00'.
static LocalTime NOON − The time of noon in the middle of the day, '12:00'.
Sr.No. | Method & Description |
---|---|
1 | Temporal adjustInto(Temporal temporal)
Adjusts the specified temporal object to have the same date and time as this object. |
2 | LocalDateTime atDate(LocalDate date)
Combines this time with a date to create a LocalDateTime. |
3 | OffsetDateTime atOffset(ZoneOffset offset)
Combines this time with an offset time to create an OffsetDateTime. |
4 | int compareTo(LocalTime other)
Compares this time to another time. |
5 | boolean equals(Object obj)
Checks if this time is equal to another time. |
6 | String format(DateTimeFormatter formatter)
Formats this time using the specified formatter. |
7 | static LocalTime from(TemporalAccessor temporal)
Obtains an instance of LocalTime from a temporal object. |
8 | int get(TemporalField field)
Gets the value of the specified field from this time as an int. |
9 | int getHour()
Gets the hour-of-day field. |
10 | long getLong(TemporalField field)
Gets the value of the specified field from this time as a long. |
11 | int getMinute()
Gets the minute-of-hour field. |
12 | int getNano()
Gets the nano-of-second field. |
13 | int getSecond()
Gets the second-of-minute field. |
14 | int hashCode()
A hash code for this time. |
15 | boolean isAfter(LocalTime other)
Checks if this time is after the specified time. |
16 | boolean isBefore(LocalTime other)
Checks if this time is before the specified time. |
17 | boolean isSupported(TemporalField field)
Checks if the specified field is supported. |
18 | boolean isSupported(TemporalUnit unit)
Checks if the specified unit is supported. |
19 | LocalTime minus(long amountToSubtract, TemporalUnit unit)
Returns a copy of this time with the specified amount subtracted. |
20 | LocalTime minus(TemporalAmount amountToSubtract)
Returns a copy of this time with the specified amount subtracted. |
21 | LocalTime minusHours(long hoursToSubtract)
Returns a copy of this LocalTime with the specified number of hours subtracted. |
22 | LocalTime minusMinutes(long minutesToSubtract)
Returns a copy of this LocalTime with the specified number of minutes subtracted. |
23 | LocalTime minusNanos(long nanos)
Returns a copy of this LocalTime with the specified number of nanoseconds subtracted. |
24 | LocalTime minusSeconds(long seconds)
Returns a copy of this LocalTime with the specified number of seconds subtracted. |
25 | static LocalTime now()
Obtains the current time from the system clock in the default time-zone. |
26 | static LocalTime now(Clock clock)
Obtains the current time from the specified clock. |
27 | static LocalTime now(ZoneId zone)
Obtains the current time from the system clock in the specified time-zone. |
28 | static LocalTime of(int hour, int minute)
Obtains an instance of LocalTime from an hour and minute. |
29 | static LocalTime of(int hour, int minute, int second)
Obtains an instance of LocalTime from an hour, minute and second. |
30 | static LocalTime of(int hour, int minute, int second, int nanoOfSecond)
Obtains an instance of LocalTime from an hour, minute, second and nanosecond. |
31 | static LocalTime ofNanoOfDay(long nanoOfDay)
Obtains an instance of LocalTime from a nanos-of-day value. |
32 | static LocalTime ofSecondOfDay(long secondOfDay)
Obtains an instance of LocalTime from a second-of-day value. |
33 | static LocalTime parse(CharSequence text)
Obtains an instance of LocalTime from a text string such as 2007-12-03T10:15:30. |
34 | static LocalTime parse(CharSequence text, DateTimeFormatter formatter)
Obtains an instance of LocalTime from a text string using a specific formatter. |
35 | LocalTime plus(long amountToAdd, TemporalUnit unit)
Returns a copy of this time with the specified amount added. |
36 | LocalTime plus(TemporalAmount amountToAdd)
Returns a copy of this time with the specified amount added. |
37 | LocalTime plusHours(long hoursToAdd)
Returns a copy of this LocalTime with the specified number of hours added. |
38 | LocalTime plusMinutes(long minutesToAdd)
Returns a copy of this LocalTime with the specified number of minutes added. |
39 | LocalTime plusNanos(long nanos)
Returns a copy of this LocalTime with the specified number of nanoseconds added. |
40 | LocalTime plusSeconds(long seconds)
Returns a copy of this LocalTime with the specified number of seconds added. |
41 | <R> R query(TemporalQuery<R> query)
Queries this time using the specified query. |
42 | ValueRange range(TemporalField field)
Gets the range of valid values for the specified field. |
43 | long toNanoOfDay()
Extracts the time as nanos of day, from 0 to 24 * 60 * 60 * 1,000,000,000 - 1. |
44 | int toSecondOfDay()
Extracts the time as seconds of day, from 0 to 24 * 60 * 60 - 1. |
45 | String toString()
Outputs this date as a String, such as 10:15. |
46 | LocalTime truncatedTo(TemporalUnit unit)
Returns a copy of this LocalTime with the time truncated. |
47 | long until(Temporal endExclusive, TemporalUnit unit)
Calculates the amount of time until another time in terms of the specified unit. |
48 | LocalTime with(TemporalAdjuster adjuster)
Returns an adjusted copy of this time. |
49 | LocalTime with(TemporalField field, long newValue)
Returns a copy of this time with the specified field set to a new value. |
50 | LocalTime withHour(int hour)
Returns a copy of this LocalTime with the hour-of-day altered. |
51 | LocalTime withMinute(int minute)
Returns a copy of this LocalTime with the minute-of-hour altered. |
52 | LocalTime withNano(int nanoOfSecond)
Returns a copy of this LocalTime with the nano-of-second altered. |
53 | LocalTime withSecond(int second)
Returns a copy of this LocalTime with the second-of-minute altered. |
This class inherits methods from the following classes −