A new Date object can be created like this:
var dt = new Date();
After we’ve created a Date, we’re able to do quite a few different operations on it like set the year, month, year, or convert to local time or UTC time.
The default constructor creates a date object set to the current local date and time. The constructor is overloaded, so it can accept other parameters like the numer of milliseconds since the Unix Epoch (01/01/1970) or a date string.
var dtFromMilliseconds = new Date(1493776425266); console.log(dtFromMilliseconds)
In a past project, I had a need to add dates, determine if it was a leap year and determine number of hours between different times, which would have required quite a bit of utility code and logic. At the time, I decided to use Datejs which worked pretty well. It so adds a lot of awesome methods and other functionality that allows developers to stop worrying so much about dates and just get the project working.
Over the last year, I’ve been working a lot with AWS Lambda and started using momentjs which feels a lot more intuitive and seems to work with a lot more of the crazy formats that dates and datetimes can be found in.
Author: Brian Cline