How to get last midnight in Dart?

This should do the same

var now = DateTime.now();
var lastMidnight = DateTime(now.year, now.month, now.day);

You can use this way to get different times of this day

var tomorrowNoon = DateTime(now.year, now.month, now.day + 1, 12);

var yesterdaySixThirty = DateTime(now.year, now.month, now.day - 1, 6, 30);

Depending on what you want can absolute values be more safe because adding/subtracting Duration can result in surprises because of leap years and daylight saving time.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)