The above code will returned today's date and current time.
When using parameters with the Date object, follow the sequence of year, month, day, hours, minutes, seconds, and milliseconds.
Once you've created a Date object using the new operator, there are lots of methods you can call from that object. Most of the methods you can use the get() methods to get values from a Date object and set() methods to set values to Date object.
The methods getDate(), getDay(), getMonth(), and getFullYear() allows you to retrieve date values from a Date object. Also setDate(), setMonth(), and setFullYear() methods enable you to set the date values of a Date object.
Important date() methods
getDay(): Returns the day of a Date object
getMonth(): Returns the month of a Date object
getFullYear(): Returns the year of a Date object
getYear(): Returns the year of a Date object using only two digits
getHours(): Returns the hours of a Date object
getMinutes(): Returns the minutes of a Date object
getSeconds(): Returns the seconds of a Date object
getTime(): Returns the number of milliseconds since midnight 1/1/1970
setMonth(): Sets the months in the Date object
setFullYear(): Sets the year in the Date object
setHours(): Sets the hours in the Date object
setMinutes(): Sets the minutes in the Date object
setSeconds(): Sets the seconds in the Date object
setTime(): Sets the milliseconds after 1/1/1970
The above code will return the current year.
It will alert year 2000.
The toString() convert Date object to a string.
The parse() method returns a string date value that holds the number of milliseconds since January 01 1970 00:00:00
It willreturned 12622884200000.