How to use getHours in JavaScript
In this article, I will explain use of getHours() Method in JavaScript.
JavaScript date getHours() method
-
getHours() method of date object returns the hour of the specified date according local time.
-
In getHours() method, The returned value is an integer number between 0 and 23.
-
getHours() method returns a four-digit number
Syntax
Example
In the following example show to getHours() method returns current hours.
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Blue">JavaScript getHours() Method Example</h3>
<p id="demo">Click For Display Current Hours</p>
<button onclick="myFunction()">Click ON</button>
<script type="text/javascript">
function myFunction() {
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML = document.write("Current Hours is: " + d.getHours());
}
</script>
</body>
</html>
|
Output1
Output2
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here