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 = LocalDateTime(2000, 1, 31, 12, 23);
dt.replace(month: 4) == LocalDateTime(2000, 4, 30, 12, 23);
dt.replace(second: 59) == LocalDateTime(2000, 4, 30, 12, 23, 59);
Implementation
LocalDateTime replace(
{int? year,
int? month,
int? day,
int? hour,
int? minute,
int? second,
int? nanosecond}) {
return LocalDateTime.combine(
date.replace(year: year, month: month, day: day),
time.replace(
hour: hour,
minute: minute,
second: second,
nanosecond: nanosecond));
}