O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with dates and times

Proper date-time handling is needed in almost every data context. What does Dart give us to ease working with dates and times? Dart has the excellent built-in classes DateTime and Duration in dart:core. As a few of its many uses, you can do the following:

  • Compare and calculate with date times
  • Get every part of a date-time
  • Work with different time zones
  • Measure timespans with Stopwatch

However, the DateTime class does not provide internationalization; for this purpose, you need to use the intl package from the Dart team.

How to do it...

The following are some useful techniques (try them out in date_time.dart):

  • Formatting dates (from DateTime to a string) to standard formats, but also to any format using the package intl, as ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required