JavaScript Tutorial

Javascript Dates

This object can be used to get year, month and day. We can display a timer on the webpage by the help of JavaScript date object.

We can use different Date constructors to create date object. It provides methods to get and set day, month, year, hour, minute and seconds.

Date objects are created with the new Date() constructor. There are 4 ways to create a new date object:

Date() method

This method creates a new date object with the current date and time.

Input:-

Output:-

Date(milliseconds)

This method creates a new date object as zero time plus milliseconds.

Input:-

Output:-

Date(dateString)

This method creates a new date object from a date string.

Input:-

Output:-

Date(year, month, day, hours, minutes, seconds, milliseconds)

This method creates a new date object with a specified date and time.

Note:- JavaScript counts months from 0 to 11. January is 0. December is 11.

Input:-

Output:-

 

Go back to Previous Course