LocalDateTime class
A date and time in a particular calendar system. A LocalDateTime value does not represent an instant on the global time line, because it has no associated time zone: 'November 12th 2009 7pm, ISO calendar' occurred at different instants for different people around the world.
This type defaults to using the ISO calendar system unless a different calendar system is specified.
Values can freely be compared for equality: a value in a different calendar system is not equal to
a value in a different calendar system. However, ordering comparisons (either via the CompareTo
method
or via operators) fail with ArgumentError; attempting to compare values in different calendars
almost always indicates a bug in the calling code.
- Implemented types
- Annotations
-
- @immutable
Constructors
- LocalDateTime(int year, int month, int day, int hour, int minute, int second, {int? ms, int? us, int? ns, CalendarSystem? calendar})
- Initializes a new instance of LocalDateTime.
- LocalDateTime.dateTime(DateTime dateTime, [CalendarSystem? calendar])
-
Converts a DateTime of any kind to a LocalDateTime in the specified or ISO calendar. This does not perform
any time zone conversions, so a DateTime with a DateTime.isUtc ==
true
will still have the same day/hour/minute etc - it won't be converted into the local system time.factory - LocalDateTime.localDateAtTime(LocalDate calendarDate, LocalTime clockTime)
-
const
- LocalDateTime.now()
-
Produces a LocalDateTime based on your Clock.current and your DateTimeZone.local.
factory
Properties
- calendar → CalendarSystem
-
Gets the calendar system associated with this local date and time.
no setter
- calendarDate → LocalDate
-
Gets the date portion of this local date and time as a LocalDate in the same calendar system as this value.
final
- clockTime → LocalTime
-
Gets the time portion of this local date and time as a LocalTime.
final
- dayOfMonth → int
-
Gets the day of this local date and time within the month.
no setter
- dayOfWeek → DayOfWeek
-
Gets the week day of this local date and time expressed as an DayOfWeek value.
no setter
- dayOfYear → int
-
Gets the day of this local date and time within the year.
no setter
- era → Era
-
Gets the era of this local date and time.
no setter
- hashCode → int
-
Returns a hash code for this instance.
no setteroverride
- hourOf12HourClock → int
-
Gets the hour of the half-day of this local date and time, in the range 1 to 12 inclusive.
no setter
- hourOfDay → int
-
Gets the hour of day of this local date and time, in the range 0 to 23 inclusive.
no setter
- microsecondOfSecond → int
-
Gets the nanosecond of this local time within the second, in the range 0 to 999,999,999 inclusive.
no setter
- millisecondOfSecond → int
-
Gets the millisecond of this local date and time within the second, in the range 0 to 999 inclusive.
no setter
- minuteOfHour → int
-
Gets the minute of this local date and time, in the range 0 to 59 inclusive.
no setter
- monthOfYear → int
-
Gets the month of this local date and time within the year.
no setter
- nanosecondOfSecond → int
-
Gets the nanosecond of this local time within the second, in the range 0 to 999,999,999 inclusive.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secondOfMinute → int
-
Gets the second of this local date and time within the minute, in the range 0 to 59 inclusive.
no setter
- year → int
-
Gets the year of this local date and time.
This returns the 'absolute year', so, for the ISO calendar,
a value of 0 means 1 BC, for example.
no setter
- yearOfEra → int
-
Gets the year of this local date and time within its era.
no setter
Methods
-
add(
Period period) → LocalDateTime - Adds a period to this local date/time. Fields are added in the order provided by the period.
-
addDays(
int days) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of days added.
-
addHours(
int hours) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of hours added.
-
addMicroseconds(
int microseconds) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of ticks added.
-
addMilliseconds(
int milliseconds) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of milliseconds added.
-
addMinutes(
int minutes) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of minutes added.
-
addMonths(
int months) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of months added.
-
addNanoseconds(
int nanoseconds) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of nanoseconds added.
-
addSeconds(
int seconds) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of seconds added.
-
addWeeks(
int weeks) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of weeks added.
-
addYears(
int years) → LocalDateTime - Returns a new LocalDateTime representing the current value with the given number of years added.
-
adjustDate(
LocalDate adjuster(LocalDate)) → LocalDateTime - Returns this date/time, with the given date adjuster applied to it, maintaining the existing time of day.
-
adjustTime(
LocalTime adjuster(LocalTime)) → LocalDateTime - Returns this date/time, with the given time adjuster applied to it, maintaining the existing date.
-
compareTo(
LocalDateTime? other) → int -
Indicates whether this date/time is earlier, later or the same as another one.
override
-
equals(
LocalDateTime other) → bool - Indicates whether the current object is equal to another object of the same type.
-
inUtc(
) → ZonedDateTime - Returns the mapping of this local date/time within DateTimeZone.utc.
-
inZone(
DateTimeZone zone, ZoneLocalMappingResolver resolver) → ZonedDateTime - Resolves this local date and time into a ZonedDateTime in the given time zone, following the given ZoneLocalMappingResolver to handle ambiguity and skipped times.
-
inZoneLeniently(
DateTimeZone zone) → ZonedDateTime - Returns the mapping of this local date/time within the given DateTimeZone, with 'lenient' rules applied such that ambiguous values map to the earlier of the alternatives, and 'skipped' values are shifted forward by the duration of the "gap".
-
inZoneStrictly(
DateTimeZone zone) → ZonedDateTime - Returns the mapping of this local date/time within the given DateTimeZone, with 'strict' rules applied such that an exception is thrown if either the mapping is ambiguous or the time is skipped.
-
next(
DayOfWeek targetDayOfWeek) → LocalDateTime - Returns the next LocalDateTime falling on the specified DayOfWeek, at the same time of day as this value. This is a strict 'next' - if this value on already falls on the target day of the week, the returned value will be a week later.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
periodSince(
LocalDateTime localDateTime) → Period -
Subtracts the specified date/time from this date/time, returning the result as a Period.
Cognitively similar to:
this - localDateTime
. -
periodUntil(
LocalDateTime localDateTime) → Period -
Subtracts the specified date/time from this date/time, returning the result as a Period.
Cognitively similar to:
localDateTime - this
. -
previous(
DayOfWeek targetDayOfWeek) → LocalDateTime - Returns the previous LocalDateTime falling on the specified DayOfWeek, at the same time of day as this value. This is a strict 'previous' - if this value on already falls on the target day of the week, the returned value will be a week earlier.
-
subtract(
Period period) → LocalDateTime - Subtracts a period from a local date/time. Fields are subtracted in the order provided by the period.
-
subtractDays(
int days) → LocalDateTime -
subtractHours(
int hours) → LocalDateTime -
subtractMicroseconds(
int microseconds) → LocalDateTime -
subtractMilliseconds(
int milliseconds) → LocalDateTime -
subtractMinutes(
int minutes) → LocalDateTime -
subtractMonths(
int months) → LocalDateTime -
subtractNanoseconds(
int nanoseconds) → LocalDateTime -
subtractSeconds(
int seconds) → LocalDateTime -
subtractWeeks(
int weeks) → LocalDateTime -
subtractYears(
int years) → LocalDateTime -
toDateTimeLocal(
) → DateTime - Constructs a DateTime from this value which has a DateTime.isUtc == false;
-
toString(
[String? patternText, Culture? culture]) → String -
Returns a String that represents this instance.
override
-
withCalendar(
CalendarSystem calendar) → LocalDateTime - Creates a new LocalDateTime representing the same physical date and time, but in a different calendar. The returned LocalDateTime is likely to have different date field values to this one. For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
-
withOffset(
Offset offset) → OffsetDateTime - Returns an OffsetDateTime for this local date/time with the given offset.
Operators
-
operator +(
Period period) → LocalDateTime - Adds a period to a local date/time. Fields are added in the order provided by the period. This is a convenience operator over the add method.
-
operator -(
Period period) → LocalDateTime -
Subtracts a period from a local date/time. Fields are subtracted in the order provided by the period.
This is a convenience operator over the
Minus(Period)
method. -
operator <(
LocalDateTime other) → bool - Compares two LocalDateTime values to see if the left one is strictly earlier than the right one.
-
operator <=(
LocalDateTime other) → bool - Compares two LocalDateTime values to see if the left one is earlier than or equal to the right one.
-
operator ==(
Object other) → bool -
Implements the operator == (equality).
override
-
operator >(
LocalDateTime other) → bool - Compares two LocalDateTime values to see if the left one is strictly later than the right one.
-
operator >=(
LocalDateTime other) → bool - Compares two LocalDateTime values to see if the left one is later than or equal to the right one.
Static Methods
-
difference(
LocalDateTime end, LocalDateTime start) → Period - Subtracts one date/time from another, returning the result as a Period.
-
max(
LocalDateTime x, LocalDateTime y) → LocalDateTime - Returns the later date/time of the given two.
-
min(
LocalDateTime x, LocalDateTime y) → LocalDateTime - Returns the earlier date/time of the given two.
-
minus(
LocalDateTime localDateTime, Period period) → LocalDateTime -
Subtracts the specified period from the date and time. Friendly alternative to
operator-()
. -
plus(
LocalDateTime localDateTime, Period period) → LocalDateTime -
Add the specified period to the date and time. Friendly alternative to
operator+()
.