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 packageintl
, as ...
Get Dart: Scalable Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.