Top Description Fields Constructors Methods
java.time

public final Class LocalTime

extends Object
implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, java.time.temporal.TemporalAdjuster, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor
Annotations
@ValueBased
Static Imports
java.time.temporal.ChronoField.HOUR_OF_DAY, .ChronoField.MICRO_OF_DAY, .ChronoField.MINUTE_OF_HOUR, .ChronoField.NANO_OF_DAY, .ChronoField.NANO_OF_SECOND, .ChronoField.SECOND_OF_DAY, .ChronoField.SECOND_OF_MINUTE, .ChronoUnit.NANOS

A time without a time-zone in the ISO-8601 calendar system, such as 10:15:30.

LocalTime is an immutable date-time object that represents a time, often viewed as hour-minute-second. Time is represented to nanosecond precision. For example, the value "13:45.30.123456789" can be stored in a LocalTime.

This class does not store or represent a date or time-zone. Instead, it is a description of the local time as seen on a wall clock. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.

The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. This API assumes that all calendar systems use the same representation, this class, for time-of-day.

This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. The equals method should be used for comparisons.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Field Summary

Modifier and TypeField and Description
private final byte
hour

The hour.

private static final LocalTime[]
HOURS

Constants for the local time of each hour.

pack-priv static final int
HOURS_PER_DAY

Hours per day.

public static final LocalTime
MAX

The maximum supported LocalTime, '23:59:59.999999999'.

pack-priv static final long
MICROS_PER_DAY

Microseconds per day.

pack-priv static final long
MICROS_PER_SECOND

Microseconds per second.

public static final LocalTime
MIDNIGHT

The time of midnight at the start of the day, '00:00'.

pack-priv static final long
MILLIS_PER_DAY

Milliseconds per day.

pack-priv static final long
MILLIS_PER_SECOND

Milliseconds per second.

public static final LocalTime
MIN

The minimum supported LocalTime, '00:00'.

private final byte
minute

The minute.

pack-priv static final int
MINUTES_PER_DAY

Minutes per day.

pack-priv static final int
MINUTES_PER_HOUR

Minutes per hour.

private final int
nano

The nanosecond.

pack-priv static final long
NANOS_PER_DAY

Nanos per day.

pack-priv static final long
NANOS_PER_HOUR

Nanos per hour.

pack-priv static final long
NANOS_PER_MILLI

Nanos per millisecond.

pack-priv static final long
NANOS_PER_MINUTE

Nanos per minute.

pack-priv static final long
NANOS_PER_SECOND

Nanos per second.

public static final LocalTime
NOON

The time of noon in the middle of the day, '12:00'.

private final byte
second

The second.

pack-priv static final int
SECONDS_PER_DAY

Seconds per day.

pack-priv static final int
SECONDS_PER_HOUR

Seconds per hour.

pack-priv static final int
SECONDS_PER_MINUTE

Seconds per minute.

private static final long
serialVersionUID

Serialization version.

Constructor Summary

AccessConstructor and Description
private
LocalTime(int
the hour-of-day to represent, validated from 0 to 23
hour
,
int
the minute-of-hour to represent, validated from 0 to 59
minute
,
int
the second-of-minute to represent, validated from 0 to 59
second
,
int
the nano-of-second to represent, validated from 0 to 999,999,999
nanoOfSecond
)

Constructor, previously validated.

Method Summary

Modifier and TypeMethod and Description
public Temporal

Returns:

the adjusted object, not null
adjustInto
(Temporal
the target object to be adjusted, not null
temporal
)

Implements java.time.temporal.TemporalAdjuster.adjustInto.

Adjusts the specified temporal object to have the same time as this object.
public LocalDateTime

Returns:

the local date-time formed from this time and the specified date, not null
atDate
(LocalDate
the date to combine with, not null
date
)

Combines this time with a date to create a LocalDateTime.

public OffsetTime

Returns:

the offset time formed from this time and the specified offset, not null
atOffset
(ZoneOffset
the offset to combine with, not null
offset
)

Combines this time with an offset to create an OffsetTime.

public int

Returns:

the comparator value, that is less than zero if this is before other, zero if they are equal, or greater than zero if this is after other
compareTo
(LocalTime
the other time to compare to, not null
other
)

Implements java.lang.Comparable.compareTo.

Compares this time to another time.
private static LocalTime

Returns:

the local time, not null
create
(int
the hour-of-day to represent, validated from 0 to 23
hour
,
int
the minute-of-hour to represent, validated from 0 to 59
minute
,
int
the second-of-minute to represent, validated from 0 to 59
second
,
int
the nano-of-second to represent, validated from 0 to 999,999,999
nanoOfSecond
)

Creates a local time from the hour, minute, second and nanosecond fields.

public boolean

Returns:

true if this is equal to the other time
equals
(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Checks if this time is equal to another time.
public String

Returns:

the formatted time string, not null
format
(DateTimeFormatter
the formatter to use, not null
formatter
)

Formats this time using the specified formatter.

public static LocalTime

Returns:

the local time, not null
from
(TemporalAccessor
the temporal object to convert, not null
temporal
)

Obtains an instance of LocalTime from a temporal object.

public int

Returns:

the value for the field
get
(TemporalField
the field to get, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field from this time as an int.
private int
public int

Returns:

the hour-of-day, from 0 to 23
getHour
()

Gets the hour-of-day field.

public long

Returns:

the value for the field
getLong
(TemporalField
the field to get, not null
field
)

Implements java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field from this time as a long.
public int

Returns:

the minute-of-hour, from 0 to 59
getMinute
()

Gets the minute-of-hour field.

public int

Returns:

the nano-of-second, from 0 to 999,999,999
getNano
()

Gets the nano-of-second field.

public int

Returns:

the second-of-minute, from 0 to 59
getSecond
()

Gets the second-of-minute field.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

A hash code for this time.
public boolean

Returns:

true if this is after the specified time
isAfter
(LocalTime
the other time to compare to, not null
other
)

Checks if this time is after the specified time.

public boolean

Returns:

true if this point is before the specified time
isBefore
(LocalTime
the other time to compare to, not null
other
)

Checks if this time is before the specified time.

public boolean

Returns:

true if the field is supported on this time, false if not
isSupported
(TemporalField
the field to check, null returns false
field
)

Implements java.time.temporal.TemporalAccessor.isSupported.

Checks if the specified field is supported.
public boolean

Returns:

true if the unit can be added/subtracted, false if not
isSupported
(TemporalUnit
the unit to check, null returns false
unit
)

Implements java.time.temporal.Temporal.isSupported.

Checks if the specified unit is supported.
public LocalTime

Returns:

a LocalTime based on this time with the subtraction made, not null
minus
(TemporalAmount
the amount to subtract, not null
amountToSubtract
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this time with the specified amount subtracted.
public LocalTime

Returns:

a LocalTime based on this time with the specified amount subtracted, not null
minus
(long
the amount of the unit to subtract from the result, may be negative
amountToSubtract
,
TemporalUnit
the unit of the amount to subtract, not null
unit
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this time with the specified amount subtracted.
public LocalTime

Returns:

a LocalTime based on this time with the hours subtracted, not null
minusHours
(long
the hours to subtract, may be negative
hoursToSubtract
)

Returns a copy of this LocalTime with the specified number of hours subtracted.

public LocalTime

Returns:

a LocalTime based on this time with the minutes subtracted, not null
minusMinutes
(long
the minutes to subtract, may be negative
minutesToSubtract
)

Returns a copy of this LocalTime with the specified number of minutes subtracted.

public LocalTime

Returns:

a LocalTime based on this time with the nanoseconds subtracted, not null
minusNanos
(long
the nanos to subtract, may be negative
nanosToSubtract
)

Returns a copy of this LocalTime with the specified number of nanoseconds subtracted.

public LocalTime

Returns:

a LocalTime based on this time with the seconds subtracted, not null
minusSeconds
(long
the seconds to subtract, may be negative
secondsToSubtract
)

Returns a copy of this LocalTime with the specified number of seconds subtracted.

public static LocalTime

Returns:

the current time using the system clock and default time-zone, not null
now
()

Obtains the current time from the system clock in the default time-zone.

public static LocalTime

Returns:

the current time using the system clock, not null
now
(ZoneId
the zone ID to use, not null
zone
)

Obtains the current time from the system clock in the specified time-zone.

public static LocalTime

Returns:

the current time, not null
now
(Clock
the clock to use, not null
clock
)

Obtains the current time from the specified clock.

public static LocalTime

Returns:

the local time, not null
of
(int
the hour-of-day to represent, from 0 to 23
hour
,
int
the minute-of-hour to represent, from 0 to 59
minute
)

Obtains an instance of LocalTime from an hour and minute.

public static LocalTime

Returns:

the local time, not null
of
(int
the hour-of-day to represent, from 0 to 23
hour
,
int
the minute-of-hour to represent, from 0 to 59
minute
,
int
the second-of-minute to represent, from 0 to 59
second
)

Obtains an instance of LocalTime from an hour, minute and second.

public static LocalTime

Returns:

the local time, not null
of
(int
the hour-of-day to represent, from 0 to 23
hour
,
int
the minute-of-hour to represent, from 0 to 59
minute
,
int
the second-of-minute to represent, from 0 to 59
second
,
int
the nano-of-second to represent, from 0 to 999,999,999
nanoOfSecond
)

Obtains an instance of LocalTime from an hour, minute, second and nanosecond.

public static LocalTime

Returns:

the local time, not null
ofInstant
(Instant
the instant to create the time from, not null
instant
,
ZoneId
the time-zone, which may be an offset, not null
zone
)

Obtains an instance of LocalTime from an Instant and zone ID.

This creates a local time based on the specified instant.

public static LocalTime

Returns:

the local time, not null
ofNanoOfDay
(long
the nano of day, from 0 to 24 * 60 * 60 * 1,000,000,000 - 1
nanoOfDay
)

Obtains an instance of LocalTime from a nanos-of-day value.

public static LocalTime

Returns:

the local time, not null
ofSecondOfDay
(long
the second-of-day, from 0 to 24 * 60 * 60 - 1
secondOfDay
)

Obtains an instance of LocalTime from a second-of-day value.

public static LocalTime

Returns:

the parsed local time, not null
parse
(CharSequence
the text to parse such as "10:15:30", not null
text
)

Obtains an instance of LocalTime from a text string such as 10:15.

public static LocalTime

Returns:

the parsed local time, not null
parse
(CharSequence
the text to parse, not null
text
,
DateTimeFormatter
the formatter to use, not null
formatter
)

Obtains an instance of LocalTime from a text string using a specific formatter.

public LocalTime

Returns:

a LocalTime based on this time with the addition made, not null
plus
(TemporalAmount
the amount to add, not null
amountToAdd
)

Overrides default java.time.temporal.Temporal.plus.

Returns a copy of this time with the specified amount added.
public LocalTime

Returns:

a LocalTime based on this time with the specified amount added, not null
plus
(long
the amount of the unit to add to the result, may be negative
amountToAdd
,
TemporalUnit
the unit of the amount to add, not null
unit
)

Implements java.time.temporal.Temporal.plus.

Returns a copy of this time with the specified amount added.
public LocalTime

Returns:

a LocalTime based on this time with the hours added, not null
plusHours
(long
the hours to add, may be negative
hoursToAdd
)

Returns a copy of this LocalTime with the specified number of hours added.

public LocalTime

Returns:

a LocalTime based on this time with the minutes added, not null
plusMinutes
(long
the minutes to add, may be negative
minutesToAdd
)

Returns a copy of this LocalTime with the specified number of minutes added.

public LocalTime

Returns:

a LocalTime based on this time with the nanoseconds added, not null
plusNanos
(long
the nanos to add, may be negative
nanosToAdd
)

Returns a copy of this LocalTime with the specified number of nanoseconds added.

public LocalTime

Returns:

a LocalTime based on this time with the seconds added, not null
plusSeconds
(long
the seconds to add, may be negative
secondstoAdd
)

Returns a copy of this LocalTime with the specified number of seconds added.

public <
the type of the result
R
>
R

Returns:

the query result, null may be returned (defined by the query)
query
(TemporalQuery<R>
the query to invoke, not null
query
)

Overrides default java.time.temporal.TemporalAccessor.query.

Queries this time using the specified query.
public ValueRange

Returns:

the range of valid values for the field, not null
range
(TemporalField
the field to query the range for, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.
pack-priv static LocalTime
private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

public long

Returns:

the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative
toEpochSecond
(LocalDate
the local date, not null
date
,
ZoneOffset
the zone offset, not null
offset
)

Converts this LocalTime to the number of seconds since the epoch of 1970-01-01T00:00:00Z.

public long

Returns:

the nano of day equivalent to this time
toNanoOfDay
()

Extracts the time as nanos of day, from 0 to 24 * 60 * 60 * 1,000,000,000 - 1.

public int

Returns:

the second-of-day equivalent to this time
toSecondOfDay
()

Extracts the time as seconds of day, from 0 to 24 * 60 * 60 - 1.

public String

Returns:

a string representation of this time, not null
toString
()

Overrides java.lang.Object.toString.

Outputs this time as a String, such as 10:15.
public LocalTime

Returns:

a LocalTime based on this time with the time truncated, not null
truncatedTo
(TemporalUnit
the unit to truncate to, not null
unit
)

Returns a copy of this LocalTime with the time truncated.

public long

Returns:

the amount of time between this time and the end time
until
(Temporal
the end time, exclusive, which is converted to a LocalTime, not null
endExclusive
,
TemporalUnit
the unit to measure the amount in, not null
unit
)

Implements java.time.temporal.Temporal.until.

Calculates the amount of time until another time in terms of the specified unit.
public LocalTime

Returns:

a LocalTime based on this with the adjustment made, not null
with
(TemporalAdjuster
the adjuster to use, not null
adjuster
)

Overrides default java.time.temporal.Temporal.with.

Returns an adjusted copy of this time.
public LocalTime

Returns:

a LocalTime based on this with the specified field set, not null
with
(TemporalField
the field to set in the result, not null
field
,
long
the new value of the field in the result
newValue
)

Implements java.time.temporal.Temporal.with.

Returns a copy of this time with the specified field set to a new value.
public LocalTime

Returns:

a LocalTime based on this time with the requested hour, not null
withHour
(int
the hour-of-day to set in the result, from 0 to 23
hour
)

Returns a copy of this LocalTime with the hour-of-day altered.

public LocalTime

Returns:

a LocalTime based on this time with the requested minute, not null
withMinute
(int
the minute-of-hour to set in the result, from 0 to 59
minute
)

Returns a copy of this LocalTime with the minute-of-hour altered.

public LocalTime

Returns:

a LocalTime based on this time with the requested nanosecond, not null
withNano
(int
the nano-of-second to set in the result, from 0 to 999,999,999
nanoOfSecond
)

Returns a copy of this LocalTime with the nano-of-second altered.

public LocalTime

Returns:

a LocalTime based on this time with the requested second, not null
withSecond
(int
the second-of-minute to set in the result, from 0 to 59
second
)

Returns a copy of this LocalTime with the second-of-minute altered.

pack-priv void
private Object

Returns:

the instance of Ser, not null
writeReplace
()

Writes the object using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait