JavaScript Date

JavaScript provides Date class to work with Date and its components.

Simple Date Example

To fetch the current system date, use Date() class with no arguments to the constructor. Following example demonstrates the use of Date() constructor.

index.html

ADVERTISEMENT

Get Date in Milliseconds

To fetch the current system date in milliseconds (counted from 1st Jan, 1970), use Date().getTime().

index.html

Initialize to a specific Date

You may also initialize the Date object with a specific date using one of the following constructors.

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

Following is an example demonstrating the three Constructors mentioned above.

index.html

Conclusion

In this JavaScript Tutorial, we learned about Date, and its constructors to set Date Object to a specific date.