JavaScript Date


JavaScript Date object can be used to get date and time.

It provides methods to get and set day, month, year, hour, minute, second and millisecond.

JavaScript will, by default, use the browser's time zone and display a date as a full text string.

The date objects are created with new Date() constructor.

In JavaScript, we can create a new date object using any of the following 4 ways:

a. new Date()
b. new Date(year, month, day, hours, minutes, seconds, milliseconds)
c. new Date(milliseconds)
d. new Date(date string)


The new Date() method creates a new date object with current date and time.

For example, the following code will store today’s date and time in variable “today”.

    var today = new Date();


Note: JavaScript counts months from 0 to 11 means January is 0 and December is 11. Also first day of the week (0) means Sunday.