Know more about how to create date object in javascript

Get support on JavaScript,jQuery, AJAX and other related technology.
Post Reply
admin
Site Admin
Posts: 44

Know more about how to create date object in javascript

Post by admin » Sun May 17, 2020 6:27 pm

Image

Create a new Date object
To create a new Date object use the Date() constructor:
with no arguments - Date() creates a Date instance containing the current time (up to milliseconds) and date.
with one integer argument - Date(m) creates a Date instance containing the time and date corresponding to the Epoch time (1 January, 1970 UTC) plus m milliseconds. Example: new Date(749019369738) gives the date Sun, 26 Sep 1993 04:56:09
GMT.
with a string argument - Date(dateString) returns the Date object that results after parsing dateString with Date.parse.
with two or more integer arguments - Date(i1, i2, i3, i4, i5, i6) reads the arguments as year, month, day, hours, minutes, seconds, milliseconds and instantiates the corresponding Dateobject. Note that the month is 0-indexed in JavaScript, so 0 means January and 11 means December. Example: new Date(2017, 5, 1) gives June 1st, 2017.

Exploring dates
Note that these examples were generated on a browser in the Central Time Zone of the US, during Daylight Time, as evidenced by the code. Where comparison with UTC was instructive, Date.prototype.toISOString() was used to show the date and time in UTC (the Z in the formatted string denotes UTC).
Image
Image

Post Reply