JQuery | now() method
This now() Method in jQuery is used to return a number representing the current time.
Syntax:
jQuery.now()
Parameters: The now() method does not accept any parameter.
Return Value: It returns the number representing the current time.
Example 1: In this example, the now() Method a display the number of milliseconds with innerHTML function.
<!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title >JQuery | now() method</ title > </ head > < body style = "text-align:center;" > < h1 style = "color: green" > GeeksForGeeks </ h1 > < h3 >JQuery | now() method</ h3 > < button onclick = "geek()" >Try it</ button > < p id = "demo" ></ p > < script > function geek() { var n = jQuery.now(); document.getElementById("demo").innerHTML = n/3600; } </ script > </ body > </ html > |
Output:
Before Click:
After Click:
Example 2: In this example, the now() Method a display the number of milliseconds with alertfunction.
<!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title >JQuery | now() method</ title > </ head > < body style = "text-align:center;" > < h1 style = "color: green" > GeeksForGeeks </ h1 > < h3 >JQuery | now() method</ h3 > < button onclick = "geek()" >Try it</ button > < script > function geek() { var n = jQuery.now(); alert("Number of milliseconds : " + n); } </ script > </ body > </ html > |
Output:
Before Click:
After Click: