JavaScript Date

 15 - Oct - 2021

The date object is used to create the date in javascript.

JavaScript Date Example

There is no argument in Date, here the date object displays the current date and time.


<script type="text/javascript">
  var date = new Date();

The date can be created by specifying milliseconds, date string, or year and month in the date constructor.


<script type="text/javascript"> 
    var currentDate = new Date()
    var day = currentDate.getDate()
    var month = currentDate.getMonth()
    var year = currentDate.getFullYear()
    document.write("Current Date: " + day + "-" + month + "-" + year);

JavaScript Current Time Example

Let's see the following example of display current time in javascript.


<script type="text/javascript"> 
  var currentDate =new Date();  
  var h=currentDate.getHours();  
  var m=currentDate.getMinutes();  
  var s=currentDate.getSeconds();  
  document.write("Current Time: " + h+ ":" + m+ ":" + s);