Dates

Dart brings some much needed sanity to dates and times in the browser. The answer to the question that is burning in many a JavaScript refugee’s heart is “yes”—the first month is, in fact, 1. Let the rejoicing commence.

The niceties of Dart dates do not end there. For instance, there are a number of ways to create dates.

primitives/dates.dart
 
var​ mar = DateTime.parse(​'2013-03-01 14:31:12'​);
 
// 2013-03-01 14:31:12.000
 
var​ now = ​new​ DateTime.now();
 
// 2012-12-31 23:59:59.149
 
var​ apr = ​new​ DateTime(2013, 4, 1);
 
// 2013-04-01 00:00:00.000
 
var​ may = ​new​ DateTime(2013, 5, 1, 18, 18, 18);
 
// 2013-05-01 18:18:18.000

Even better, manipulating dates is not only possible but quite nice.

 
var​ jun = ​new​ DateTime(2013, ...

Get Dart 1 for Everyone 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.