toZonedDateTime method
Converts this DateTime to a ZonedDateTime.
// Assuming the current location is Singapore.
DateTime(2023, 10, 10, 10, 30).toZonedDateTime(); // 2023-10-10 10:30[Asia/Singapore]
DateTime.utc(2023, 10, 10, 10, 30).toOffsetTime(); // 10:30Z
By default, retrieving the platform's timezone is only only supported on Windows, MacOS, Linux & web. The
Factory
timezone will be returned on all other platforms. See Timezone.platformTimezoneProvider.
Implementation
ZonedDateTime toZonedDateTime() => isUtc ?
ZonedDateTime('Etc/UTC', year, month, day, hour, minute, second, millisecond, microsecond) :
ZonedDateTime.from(Timezone.now(), year, month, day, hour, minute, second, millisecond, microsecond);