nearestDateTime property
DateTime
nearestDateTime
Returns a DateTime object that represents as closely as possible the time instant represented by this object. DateTime objects are limited to millisecond precision and cannot describe times very far in the past or future.
Implementation
DateTime get nearestDateTime {
var msSince1970 = valueInUnits(TimeInstant.system);
// Adjust for rounding to closest date
if (msSince1970 < 0.0) {
msSince1970 -= 0.5;
} else {
msSince1970 += 0.5;
}
return DateTime.fromMillisecondsSinceEpoch(msSince1970.toInt(), isUtc: true);
}