JavaScript Date


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.

Example

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

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

Example

<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);
</script>

JavaScript Current Time Example

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

Example

<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);  
</script>