withZoneSameLocal method

ZonedDateTime withZoneSameLocal(
  1. ZoneId zone
)

Creates a new ZonedDateTime with the same local date-time but different timezone.

Unlike withZoneSameInstant, this keeps the same local date-time values but changes the timezone, effectively changing the instant in time.

Example:

final original = ZonedDateTime.parse('2023-12-25T15:00:00-05:00[America/New_York]');
final sameTime = original.withZoneSameLocal(ZoneId.of('Europe/London'));

print('Original: $original');   // 15:00 in New York
print('Same local: $sameTime'); // 15:00 in London (different instant)

Implementation

ZonedDateTime withZoneSameLocal(ZoneId zone) {
  return ZonedDateTime.of(_localDateTime, zone);
}