Top 7 Date methods you should know (Dart)

Jermaine Oppong on September 14, 2018

In this tutorial, we will look at the Top 7 methods to make you productive when working with dates. Using dates come in the form of the DateTime ... [Read Full]
markdown guide
 

For those who don't want to hard-code the Date as "$September 15, 2018" or "12:00AM". you can use intl from pub.dartlang.org

At first I did the hard-code of displaying the date & time in a proper format. then I realized that there's also a package that made it easy to code it.

 

This is a pretty solid representing of Dart. I feel like you can know a lot from how a language treats dates.

 

Pleased to see that Dart is quite sane in its API and dates/times carry around the time zone.

I still get frustrated because after many years I still have to deal with date times without a timezone in Python. From the standard library:

>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 9, 15, 1, 51, 58, 769069)
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 9, 14, 23, 52, 4, 568886)
>>> datetime.datetime.now().isoformat()
'2018-09-15T01:52:14.024139'
>>> datetime.datetime.utcnow().isoformat()
'2018-09-14T23:52:23.090149'

Neither the local time, now(), nor the UTC time carry the time zone so if you pass that around you're bound to mess it up, they call those "naive datetimes" vs "time zone aware datetimes" but I call them "useless datetimes" :D

No wonder Python has so many datetime libraries (each word links to a different library :D)

 

Great article!

For those who don't know there is MomentJS for JavaScript that implements all these methods.

 

Thanks Sergiu. I grant that MomentJS implements some useful util methods for dates.

However the beauty here is that all these methods come inbuilt with Dart, so no extra dependencies needed.

 
code of conduct - report abuse