LocalTime
LocalTime
Class
LocalTime
ClassThe LocalTime
class represents a time of day without a date and time zone. It provides methods for creating, manipulating, and comparing time values.
Static Methods
now()
now()
Returns the current time.
Example Usage:
parse(text: String)
parse(text: String)
Parses the input text to create a
LocalTime
instance.Example Usage:
of(hour: Integer, minute: Integer, second: Integer)
of(hour: Integer, minute: Integer, second: Integer)
Creates a
LocalTime
instance with the specified hour, minute, and second values.Example Usage:
of(hour: Integer, minute: Integer, second: Integer, nanoOfSecond: Integer)
of(hour: Integer, minute: Integer, second: Integer, nanoOfSecond: Integer)
Creates a
LocalTime
instance with the specified hour, minute, second, and nanosecond values.Example Usage:
Getter Methods
getHour()
getHour()
Gets the hour-of-day field.
Returns the hour-of-day, from 0 to 23.
Example Usage:
getMinute()
getMinute()
Gets the minute-of-hour field.
Returns the minute-of-hour, from 0 to 59.
Example Usage:
getSecond()
getSecond()
Gets the second-of-minute field.
Returns the second-of-minute, from 0 to 59.
Example Usage:
getNano()
getNano()
Gets the nano-of-second field.
Returns the nano-of-second, from 0 to 999,999,999.
Example Usage:
Time Manipulation Methods
plusHours(hoursToAdd: Long)
plusHours(hoursToAdd: Long)
Adds the specified number of hours to the current time and returns a new
LocalTime
instance.Example Usage:
plusMinutes(minutesToAdd: Long)
plusMinutes(minutesToAdd: Long)
Adds the specified number of minutes to the current time and returns a new
LocalTime
instance.Example Usage:
plusSeconds(secondsToAdd: Long)
plusSeconds(secondsToAdd: Long)
Adds the specified number of seconds to the current time and returns a new
LocalTime
instance.Example Usage:
plusNanos(nanosToAdd: Long)
plusNanos(nanosToAdd: Long)
Adds the specified number of nanoseconds to the current time and returns a new
LocalTime
instance.Example Usage:
minusHours(hoursToSubtract: Long)
minusHours(hoursToSubtract: Long)
Subtracts the specified number of hours from the current time and returns a new
LocalTime
instance.Example Usage:
minusMinutes(minutesToSubtract: Long)
minusMinutes(minutesToSubtract: Long)
Subtracts the specified number of minutes from the current time and returns a new
LocalTime
instance.Example Usage:
minusSeconds(secondsToSubtract: Long)
minusSeconds(secondsToSubtract: Long)
Subtracts the specified number of seconds from the current time and returns a new
LocalTime
instance.Example Usage:
minusNanos(nanosToSubtract: Long)
minusNanos(nanosToSubtract: Long)
Subtracts the specified number of nanoseconds from the current time and returns a new
LocalTime
instance.Example Usage:
Comparison Methods
isBefore(otherInstant: LocalTime)
isBefore(otherInstant: LocalTime)
Checks if the current time is before the specified
LocalTime
instance.Returns
true
if the current time is beforeotherInstant
,false
otherwise.Example Usage:
isAfter(otherInstant: LocalTime)
isAfter(otherInstant: LocalTime)
Checks if the current time is after the specified
LocalTime
instance.Returns
true
if the current time is afterotherInstant
,false
otherwise.Example Usage:
Conversion Method
toString()
toString()
Converts the
LocalTime
to a string representation in the format "HH:mm:ss".Example Usage:
Last updated