Skip to content
Justice Tech School

Dart Date and Time

DateTime.now gives the current moment. Create dates with DateTime(y, m, d), add Duration and compare with isBefore or difference.

Example
void main() {
  var d = DateTime(2026, 3, 15);
  var later = d.add(const Duration(days: 30));
  print(later.month);
  print(later.difference(d).inDays);
  print(d.isBefore(later));
}

Exercise

Add time to a date.

d.(Duration(days: 1))

Quiz Test

Which class holds a date and time?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.