JavaScript Date now() Method

Below is the example of Date now() method.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script>
      
      // Use of method Date.now()
      var A = Date.now();
      
      // Printing the number of millisecond elapsed 
      document.write("The time elapsed in millisecond is: " + A);
      
    </script>    

    chevron_right

    
    

  • Output:
    The time elapsed in millisecond is: 1529644667834

The date.now() method is used to returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Since now() is a static method of Date, it will always be used as Date.now().
Syntax:

var A = Date.now();

Parameters: This method does not accepts any parameter.
Return Values: It returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.

More codes for the above method are as follows:
Program 1: To get the current date, use the code below.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  // Use of Date.now() method
  var d = Date(Date.now());
  
  // Converting the number of millisecond 
  // in date string
  a = d.toString()
  
  // Printing the current date                    
  document.write("The current date is: " + a) 
  
</script>

chevron_right


Output:



The current date is: Fri Jun 22 2018 10:54:33 
GMT+0530 (India Standard Time)

Program 2: The Date(Date.now()) is same as Date(), so the same result can be achieved i.e, current date using the following code.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  // Using Date() method
  var d = Date();
    
  // Converting the number value to string
  a = d.toString() 
    
  // Printing the current date
  document.write("The current date is: " + a)
    
</script>

chevron_right


Output:

The current date is: Fri Jun 22 2018 11:02:01 
GMT+0530 (India Standard Time)

Supported Browsers: The browsers supported by JavaScript Date now() method are listed below:

  • Google Chrome
  • Internet Explorer 9.0
  • Mozilla Firefox
  • Opera
  • Safari

full-stack-img




My Personal Notes arrow_drop_up

Recommended Posts: