How to use getHours in JavaScript

In this article, I will explain use of getHours() Method in JavaScript.
  • 1628

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

Date.getHours()

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

getHours 1.jpg

Output2

getHours 2.jpg

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.