replace method
Returns a new datetime with one or more fields replaced.
Uses the largest valid day if the day is invalid in the resulting month.
var dt = OffsetDateTime(2000, 1, 31, 12, 23);
dt.replace(month: 4) == OffsetDateTime(2000, 4, 30, 12, 23);
dt.replace(second: 59) == OffsetDateTime(2000, 4, 30, 12, 23, 59);
Implementation
OffsetDateTime replace({
int? year,
int? month,
int? day,
int? hour,
int? minute,
int? second,
int? nanosecond,
ZoneOffset? offset,
}) {
return OffsetDateTime.fromLocalDateTime(
_dateTime.replace(
year: year,
month: month,
day: day,
hour: hour,
minute: minute,
second: second,
nanosecond: nanosecond),
offset ?? this.offset);
}