close
The Wayback Machine - https://web.archive.org/web/20201019083807/https://www.geeksforgeeks.org/javascript-date/amp/

JavaScript | Date

The Date object in JavaScript is used to represent a moment of time. This time value is since 1 January 1970 UTC (Coordinated Universal Time). We can create a date using the Date object by calling the new Date() constructor as shown in the below syntax.

Syntax:

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

Parameters: All of the parameters as shown in the above syntax are described below:

Return Values: It returns the present date and time if nothing as the parameter is given otherwise it return the date format and time in which parameter is given.

Let’s see JavaScript programs on Date object.



Errors and Exceptions: To check this you have to check in console.

Application: It has many application such as for getting the exact current date and time. Below program prints the current date and time using the Date() object.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  // If nothing as parameter is given, it 
  // represent the present date and time.
  var A = new Date();
  
  // Printing present date and time.
  document.write(A);
</script>
chevron_right

Output:

Wed Mar 21 2018 20:44:40 GMT+0530 (India Standard Time)

Supported Browsers: The browsers supported by JavaScript Date are listed below:





Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :