D3.js now() function

The d3.now() function in D3.js is used to return the current time according to the performance.now() function available in the javascript or If this is not available than date.now() function is used to return the current time.

Syntax:

d3.now()

Parameters: It does not take any parameters.

Return Value: It returns the time of the dataType string.

Note: The output may vary on different machines.



Below given are a few examples of the above function.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width,
                 initial-scale=1.0">
  <title>Document</title>
</head>
<style>
</style>
<body>
  <!-- Fetching from CDN of D3.js -->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js">
  </script>
  <script>
    console.log("Current time using d3.now(): ")
    console.log(d3.now())
    console.log(d3.now())
    console.log(d3.now())
    console.log(d3.now())
    console.log(d3.now())
    console.log(d3.now())
    console.log(d3.now())
  </script>
</body>
</html>

chevron_right


Output:

Example 2: Note the difference in performance.now() and d3.now().

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width,
                 initial-scale=1.0">
  <title>Document</title>
</head>
<style>
</style>
<body>
  <!-- Fetching from CDN of D3.js -->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js">
  </script>
  <script>
    console.log("Current time using d3.now(): ")
    console.log(d3.now())
    console.log("Current time using performance.now(): ")
    console.log(performance.now())
      
    console.log("Current time using performance.now(): ")
    console.log(performance.now())
    console.log("Current time using d3.now(): ")
    console.log(d3.now())
  </script>
</body>
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

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 :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.