const myDate = new Date(); console.log(myDate);
To avail of the details from the date, you can collect them in variables by specifying it.
var d = new Date(124125321471); console.log(d.toString());
Fri Dec 07 1973 20:45:21 GMT+0530 (India Standard Time)
var d = new Date('2016-03-02T11:30:00'); console.log(d.toString());
Wed Mar 02 2016 11:30:00 GMT+0530 (India Standard Time)
This method is generally used for constructing instances.
var d = new Date(year, index of month, date, hours, minutes, seconds, milliseconds); var d = new Date(2016, 03, 02, 11, 30, 27, 0);
//you can also add time zones
NOTE: Index of months starts from 0 and ends on 11 and the last parameter is stating month in the function.
There are different methods to get specific data out of a given date. For instance, if the user wants to acquire the year or month or just the date from the given data.
var d = new Date(2016, 03, 02, 11, 30, 27, 0); console.log(d.getFullYear());
There are many others :
If the new Date(); is kept empty that is without any arguments then all the above codes will show you the respective date, time, year, and more according to your local time zone.
Fri Apr 15 2016 11:30:27 GMT+0530 (India Standard Time)
Similarly every aspect of the value from new Date(); can be changed, there are