There are four main ways to create an instance of the Date object: current date-time, a specific date-time in the past or the future, through milliseconds, and last but not least, the give-me-anything and I’ll turn it into a date.
Creating a date
In its simplest form, the Date object instantiates the current date-time, based on the browser’s location.
Specific date-time allows for the creation of a specific date down to the minute and second.
The millisecond way will instantiate a Date object X milliseconds after January 1 1970. So in the example below, it catapulted us to the year 2231.
Lastly, in written form the date can be complete or incomplete and the format is fairly permissive. Month and year, no day, day of the week…
First, these methods allow the programmer to translate the object into a human-readable string.
Then we have getter and setter methods. Below are some of the methods that can be used to have granular access to certain portions of the Date object.
Lastly, setter methods provide the ability to change the date after it was instantiated.
A Useful Example
Aside from the self-evident use case of using the Date object to, for example, mark the date-time this post was originally written in, it can also be used to determine how long a particular computer takes to execute a procedure. Useful in the realms of optimization and good programming.