LocalDate.dateTime constructor

LocalDate.dateTime(
  1. DateTime dateTime, [
  2. CalendarSystem? calendar
])

Converts a DateTime of any kind to a LocalDate in the specified or ISO calendar, ignoring the time of day. This does not perform any time zone conversions, so a DateTime with a DateTime.isUtc of true will still represent the same year/month/day as it does in UTC - it won't be converted into the local system time.

  • dateTime: Value to convert into a Time Machine local date
  • calendar: The calendar system to convert into, defaults to ISO calendar

Returns: A new LocalDate with the same values as the specified DateTime.

Implementation

factory LocalDate.dateTime(DateTime dateTime, [CalendarSystem? calendar])
{
  int days = Platform.isWeb
      ? (dateTime.millisecondsSinceEpoch + dateTime.timeZoneOffset.inMilliseconds) ~/ TimeConstants.millisecondsPerDay
      : (dateTime.microsecondsSinceEpoch + dateTime.timeZoneOffset.inMicroseconds) ~/ TimeConstants.microsecondsPerDay;
  return LocalDate.fromEpochDay(days, calendar);
}