LocalDate class

Represents a calendar date without time or timezone.

This class provides date-only operations such as computing weekdays, adding or subtracting days/months/years, and converting from/to strings.

It ensures valid dates (e.g. February never has more than 29 days).

Example

final date = LocalDate(2024, 6, 27);
print(date); // "2024-06-27"
Implemented types

Constructors

LocalDate(int year, int month, int day)
Creates a new LocalDate instance for a specific year, month, and day.
LocalDate.fromDateTime(DateTime dateTime)
Creates a LocalDate from a DateTime object.
factory
LocalDate.now()
Returns the current date as a LocalDate.
factory
LocalDate.parse(String dateString)
Parses a LocalDate from an ISO string in the format YYYY-MM-DD.
factory

Properties

day int
final
dayOfWeek int
Returns the ISO 8601 day of the week (1 = Monday, ..., 7 = Sunday).
no setter
dayOfYear int
Returns the ordinal day of the year (1 to 365 or 366).
no setter
hashCode int
The hash code for this object.
no setteroverride
isLeapYear bool
Returns true if this date's year is a leap year.
no setter
lengthOfMonth int
Returns the number of days in this date's month.
no setter
lengthOfYear int
Returns the number of days in this date's year (365 or 366).
no setter
month int
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
year int
final

Methods

compareTo(LocalDate other) int
Compares this date with another.
override
isAfter(LocalDate other) bool
Returns true if this date is after other.
isBefore(LocalDate other) bool
Returns true if this date is before other.
isEqual(LocalDate other) bool
Returns true if this date is the same as other.
minusDays(int days) LocalDate
Returns a new LocalDate with days subtracted.
minusMonths(int months) LocalDate
Returns a new LocalDate with months subtracted.
minusWeeks(int weeks) LocalDate
Returns a new LocalDate with weeks subtracted.
minusYears(int years) LocalDate
Returns a new LocalDate with years subtracted.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
plusDays(int days) LocalDate
Returns a new LocalDate with days added.
plusMonths(int months) LocalDate
Returns a new LocalDate with months added.
plusWeeks(int weeks) LocalDate
Returns a new LocalDate with weeks added.
plusYears(int years) LocalDate
Returns a new LocalDate with years added.
toDateTime() DateTime
Converts this date to a DateTime set to midnight.
toString() String
Returns the ISO 8601 date string in format YYYY-MM-DD.
override

Operators

operator ==(Object other) bool
The equality operator.
override