copyWith method

  1. @useResult
ZonedDateTime copyWith({
  1. Timezone? timezone,
  2. int? year,
  3. int? month,
  4. int? day,
  5. int? hour,
  6. int? minute,
  7. int? second,
  8. int? millisecond,
  9. int? microsecond,
})

Returns a copy of this with the updated units of time.

final foo = ZonedDateTime('Asia/Singapore', 2023, 4, 15);
foo.copyWith(day: 20); // 2023-04-20T00:00+08:00[Asia/Singapore]

Implementation

@useResult ZonedDateTime copyWith({Timezone? timezone, int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond}) =>
  ZonedDateTime.from(
    timezone ?? this.timezone,
    year ?? this.year,
    month ?? this.month,
    day ?? this.day,
    hour ?? this.hour,
    minute ?? this.minute,
    second ?? this.second,
    millisecond ?? this.millisecond,
    microsecond ?? this.microsecond,
  );