LocalDateTime class
A date with a time and timezone component, where the timezone is equal to that of the host system.
This class exists because Dart's core DateTime class can be local or UTC, but not in a typesafe way. This class is always local.
If you only need a date, consider using LocalDate instead. If you want a UTC timestamp, consider using UtcDateTime instead.
- Implemented types
Constructors
- LocalDateTime(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0])
-
Constructs a LocalDateTime from a
year,month,day,hour,minute,second,millisecondandmicrosecond. - LocalDateTime.fromCoreDateTime(DateTime dateTime)
-
Creates a LocalDateTime from an unspecified type of DateTime.
factory
- LocalDateTime.fromCoreLocalDateTime(DateTime local)
-
Creates a LocalDateTime from a "local" DateTime.
factory
- LocalDateTime.fromCoreUtcDateTime(DateTime utc)
-
Creates a LocalDateTime from a "UTC" DateTime.
factory
- LocalDateTime.fromIso8601String(String iso8601)
-
Constructs a LocalDateTime from a local ISO-8601 string.
factory
- LocalDateTime.now()
-
Constructs a LocalDateTime with the current date and time according to
the host system's clock.
factory
Properties
- day → int
-
The day part of the local date-time.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hour → int
-
The hour part of the local date-time.
no setter
- isFuture → bool
-
Returns true if this date-time is in the future (has not yet happened).
no setter
- isLastDayOfMonth → bool
-
Returns true if this date-time is in the last day of its month.
no setter
- isPast → bool
-
Returns true if this date-time is in the past (has already happened).
no setter
- microsecond → int
-
The microsecond part of the local date-time.
no setter
- millisecond → int
-
The millisecond part of the local date-time.
no setter
- minute → int
-
The minute part of the local date-time.
no setter
- month → int
-
The month part of the local date-time.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- second → int
-
The second part of the local date-time.
no setter
- weekday → int
-
Returns the weekday of this date-time, where Monday is 1 and Sunday is 7.
no setter
- year → int
-
The year part of the local date-time.
no setter
Methods
-
add(
Duration duration) → LocalDateTime -
Returns a new LocalDateTime with the given
durationadded to this. -
addDays(
int days) → LocalDateTime -
Return a new LocalDateTime offset by the given number of
days. -
addMonths(
int months) → LocalDateTime -
Return a new LocalDateTime offset by the given number of
months. -
addYears(
int years) → LocalDateTime -
Return a new LocalDateTime offset by the given number of
years. -
compareTo(
LocalDateTime other) → int -
Compares this object to another object.
override
-
copyWith(
{int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond}) → LocalDateTime - Returns a new LocalDateTime with optionally overridden values.
-
difference(
LocalDateTime other) → Duration -
Returns the difference between this date-time and
other. -
isAfter(
LocalDateTime other) → bool -
Returns true if this date-time happens after
other. -
isBefore(
LocalDateTime other) → bool -
Returns true if this date-time happens before
other. -
isSameDayAs(
LocalDateTime other) → bool -
Returns true if this date-time happens on the same day as
other. -
isSameMomentAs(
LocalDateTime other) → bool -
Returns true if this date-time happens at the exact same moment as
other. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
subtract(
Duration duration) → LocalDateTime -
Returns a new LocalDateTime with the given
durationsubtracted from this. -
subtractDays(
int days) → LocalDateTime -
Return a new LocalDateTime offset by the given number of
days. -
subtractMonths(
int months) → LocalDateTime -
Return a new LocalDateTime offset by the given number of
months. -
subtractYears(
int years) → LocalDateTime -
Return a new LocalDateTime offset by the given number of
years. -
toCoreLocal(
) → DateTime - Returns a "local" DateTime equivalent of this LocalDateTime.
-
toCoreUtc(
) → DateTime - Returns a "UTC" DateTime equivalent of this LocalDateTime.
-
toIso8601String(
) → String - Returns an ISO-8601 full-precision extended format representation.
-
toLocalDate(
) → LocalDate - Returns a LocalDate equivalent of this LocalDateTime.
-
toString(
) → String -
A string representation of this object.
override
-
toUtcDateTime(
) → UtcDateTime - Returns a UtcDateTime equivalent of this LocalDateTime.
Operators
-
operator <(
LocalDateTime other) → bool -
operator <=(
LocalDateTime other) → bool -
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
LocalDateTime other) → bool -
operator >=(
LocalDateTime other) → bool
Constants
- april → const int
- august → const int
- daysPerWeek → const int
- december → const int
- february → const int
- friday → const int
- january → const int
- july → const int
- june → const int
- march → const int
- may → const int
- monday → const int
- monthsPerYear → const int
- november → const int
- october → const int
- saturday → const int
- september → const int
- sunday → const int
- thursday → const int
- tuesday → const int
- wednesday → const int