THE DATE TYPE
The ECMAScript Date
type is based on an early version of java.util.Date
from Java. As such, the Date
type stores dates as the number of milliseconds that have passed since midnight on January 1, 1970 UTC (Universal Time Code). Using this data storage format, the Date
type can accurately represent dates 285,616 years before or after January 1, 1970.
To create a date object, use the new operator along with the Date
constructor, like this:
let now = new Date();
When the Date
constructor is used without any arguments, the created object is assigned the current date and time. To create a date based on another date or time, you must pass in the millisecond representation of the date (the number of milliseconds after midnight, January 1, 1970 UTC, the Unix epoch). To aid in this process, ECMAScript provides two methods: Date.parse()
and Date.UTC()
.
The Date.parse()
method accepts a string argument representing a date. It attempts to convert the string into a millisecond representation...