D3.js now() function
Last Updated :
29 Jul, 2020
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:
<!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 >
< script type = "text/javascript"
</ 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 >
|
Output:
Example 2: Note the difference in performance.now() and d3.now().
<!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 >
< script type = "text/javascript"
</ 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 >
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...