![]() |
VOOZH | about |
A DateTime object is a point in time. The time zone is either UTC or the local time zone. Accurate date-time handling is required in almost every data context. Dart has the marvelous built-in classes for date time and duration in dart:core.
Example:
Output:
Current Date and Time: 2025-04-03 08:14:02.503
Y2K Date (Jan 1, 2000): 2000-01-01 00:00:00.000
Y2K Date (Jan 2, 2000): 2000-01-02 00:00:00.000
Y2K Date (UTC, Jan 1, 2000): 2000-01-01 00:00:00.000Z
Y2K Date from Unix Timestamp (UTC): 2000-01-01 00:00:00.000Z
Y2K Date from ISO 8601 String: 2000-01-01 00:00:00.000Z
The fromMillisecondsSinceEpoch property of a date returns the number of milliseconds since the Unix epoch—January 1, 1970, UTC.
Example:
Output:
Y2K UTC Date Matches Expected Timestamp:
true
Unix Epoch Date Matches Expected Timestamp:
true
The Duration class can calculate the difference between two dates and move the date forward or backward.
Example:
Output:
Year after adding 366 days:
true
Month after subtracting 30 days:
true
Difference in days between Y2K and Y2001:
true
Dart's DateTime and Duration classes offer robust tools for handling dates, times, and time zones. Whether you need to compare dates, calculate durations, manipulate timestamps, or parse formatted date strings, these built-in classes make time-related operations in your applications much easier.