LocalDate
LocalDate
Class
LocalDate
ClassThe LocalDate
class represents a date (year, month, and day) without a time or time zone. It provides methods for creating, manipulating, and comparing date values.
Static Methods
now()
now()
Returns the current date.
Example Usage:
parse(text: String)
parse(text: String)
Parses the input text to create a
LocalDate
instance.Example Usage:
of(year: Integer, month: Integer, dayOfMonth: Integer)
of(year: Integer, month: Integer, dayOfMonth: Integer)
Creates a
LocalDate
instance with the specified year, month, and day values.Example Usage:
ofYearDay(year: Integer, dayOfYear: Integer)
ofYearDay(year: Integer, dayOfYear: Integer)
Creates a
LocalDate
instance based on the year and day of the year.Example Usage:
ofEpochDay(epochDay: Long)
ofEpochDay(epochDay: Long)
Creates a
LocalDate
instance based on the number of days since the epoch (January 1, 1970).Example Usage:
Getter Methods
getYear()
getYear()
Gets the year field.
Returns the year as an
int
value.Example Usage:
getMonthValue()
getMonthValue()
Gets the month-of-year field from 1 to 12.
Returns the month as an
int
from 1 to 12.Example Usage:
getDayOfMonth()
getDayOfMonth()
Gets the day-of-month field.
Returns the day-of-month as an
int
from 1 to 31.Example Usage:
getDayOfYear()
getDayOfYear()
Gets the day-of-year field.
Returns the day-of-year as an
int
from 1 to 365 (or 366 in a leap year).Example Usage:
Date Manipulation Methods
minusYears(yearsToSubtract: Long)
minusYears(yearsToSubtract: Long)
Returns a new
LocalDate
with the specified number of years subtracted.Example Usage:
minusMonths(monthsToSubtract: Long)
minusMonths(monthsToSubtract: Long)
Returns a new
LocalDate
with the specified number of months subtracted.Example Usage:
minusWeeks(weeksToSubtract: Long)
minusWeeks(weeksToSubtract: Long)
Returns a new
LocalDate
with the specified number of weeks subtracted.Example Usage:
minusDays(daysToSubtract: Long)
minusDays(daysToSubtract: Long)
Returns a new
LocalDate
with the specified number of days subtracted.Example Usage:
plusDays(daysToAdd: Long)
plusDays(daysToAdd: Long)
Returns a new
LocalDate
with the specified number of days added.Example Usage:
daysUntil(endDate: LocalDate)
daysUntil(endDate: LocalDate)
Calculates the number of days until the specified end date.
Example Usage:
monthsUntil(endDate: LocalDate)
monthsUntil(endDate: LocalDate)
Calculates the number of months until the specified end date.
Example Usage:
toEpochDay()
toEpochDay()
Returns the number of days since the epoch (typically January 1, 1970).
Example Usage:
Comparison Methods
isBefore(other: LocalDate)
isBefore(other: LocalDate)
Checks if the current date is before the specified date.
Returns
true
if the current date is beforeother
,false
otherwise.Example Usage:
isAfter(other: LocalDate)
isAfter(other: LocalDate)
Checks if the current date is after the specified date.
Returns
true
if the current date is afterother
,false
otherwise.Example Usage:
Date-Time Combination Methods
atStartOfDay()
atStartOfDay()
Combines the date with the time of midnight to create a
LocalDateTime
at the start of the date.Example Usage:
atTime(time: LocalTime)
atTime(time: LocalTime)
Combines the date with the specified
LocalTime
to create aLocalDateTime
.Example Usage:
atTime(hour: Integer, minute: Integer, second: Integer)
atTime(hour: Integer, minute: Integer, second: Integer)
Combines the date with the specified hour, minute, and second to create a
LocalDateTime
.Example Usage:
Last updated