LocalDateTime class
A date-time object without a timezone, composed of a LocalDate and LocalTime.
This class represents a specific moment on a calendar, combining a date and time without referencing any timezone. It is immutable and supports arithmetic and comparison operations.
Example:
final dateTime = LocalDateTime.of(2024, 12, 31, 23, 59);
print(dateTime); // 2024-12-31T23:59:00
- Implemented types
Constructors
- LocalDateTime(LocalDate date, LocalTime time)
- A date-time object without a timezone, composed of a LocalDate and LocalTime.
- LocalDateTime.fromDateTime(DateTime dateTime)
-
Creates a LocalDateTime from a Dart DateTime instance.
factory
- LocalDateTime.now()
-
Returns the current local date and time.
factory
- LocalDateTime.of(int year, int month, int day, int hour, int minute, [int second = 0, int millisecond = 0])
- Creates a LocalDateTime from individual components.
- LocalDateTime.parse(String dateTimeString)
-
Parses a string in ISO 8601 format:
YYYY-MM-DDTHH:mm[:ss[.SSS]]
factory
Properties
- date → LocalDate
-
The date component.
final
- day → int
-
The day component of the date.
no setter
- dayOfWeek → int
-
The ISO weekday number, where Monday = 1 and Sunday = 7.
no setter
- dayOfYear → int
-
The day of the year (1–365 or 366).
no setter
- hashCode → int
-
Generates a hash code for this object.
no setteroverride
- hour → int
-
The hour component of the time (0–23).
no setter
- millisecond → int
-
The millisecond component of the time (0–999).
no setter
- minute → int
-
The minute component of the time (0–59).
no setter
- month → int
-
The month component of the date (1–12).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- second → int
-
The second component of the time (0–59).
no setter
- time → LocalTime
-
The time component.
final
- year → int
-
The year component of the date.
no setter
Methods
-
compareTo(
LocalDateTime other) → int -
Compares two LocalDateTime instances chronologically.
override
-
isAfter(
LocalDateTime other) → bool -
Returns true if this instance is later than
other
. -
isBefore(
LocalDateTime other) → bool -
Returns true if this instance is earlier than
other
. -
isEqual(
LocalDateTime other) → bool -
Returns true if this instance represents the same date and time as
other
. -
minus(
Duration duration) → LocalDateTime - Subtracts a Duration from this LocalDateTime.
-
minusDays(
int days) → LocalDateTime - Subtracts days from the date component.
-
minusHours(
int hours) → LocalDateTime - Subtracts hours from the time component.
-
minusMilliseconds(
int milliseconds) → LocalDateTime - Subtracts milliseconds from the time component.
-
minusMinutes(
int minutes) → LocalDateTime - Subtracts minutes from the time component.
-
minusMonths(
int months) → LocalDateTime - Subtracts months from the date component.
-
minusSeconds(
int seconds) → LocalDateTime - Subtracts seconds from the time component.
-
minusWeeks(
int weeks) → LocalDateTime - Subtracts weeks from the date component.
-
minusYears(
int years) → LocalDateTime - Subtracts years from the date component.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
plus(
Duration duration) → LocalDateTime - Adds a Duration to this LocalDateTime.
-
plusDays(
int days) → LocalDateTime - Adds a number of days to the date component.
-
plusHours(
int hours) → LocalDateTime - Adds hours to the time component.
-
plusMilliseconds(
int milliseconds) → LocalDateTime - Adds milliseconds to the time component.
-
plusMinutes(
int minutes) → LocalDateTime - Adds minutes to the time component.
-
plusMonths(
int months) → LocalDateTime - Adds months to the date component.
-
plusSeconds(
int seconds) → LocalDateTime - Adds seconds to the time component.
-
plusWeeks(
int weeks) → LocalDateTime - Adds weeks to the date component.
-
plusYears(
int years) → LocalDateTime - Adds years to the date component.
-
toDateTime(
) → DateTime - Converts this instance to a standard DateTime.
-
toLocalDate(
) → LocalDate - Returns the date component only.
-
toLocalTime(
) → LocalTime - Returns the time component only.
-
toString(
) → String -
ISO 8601 formatted string:
YYYY-MM-DDTHH:mm:ss[.SSS]
override
Operators
-
operator ==(
Object other) → bool -
Compares this LocalDateTime to another for equality.
override