Skip to content
Advertisements

JavaScript Date.getHours()

Why getHours ?

The Javascript Date.getHours () method returns data based on the specified date and time. As a result of this process, it returns us the time. The value returned by getHours () is an integer between 0 and 23.

Syntax:

Date.getHours()

return: Returns the hour in the specified date according to local time.


JavaScript Date getHours Examples

Example 1

You can reach the time of day with the date.getHours method.

        var now = new Date();
        console.log(now.getHours());

output:

20


Example 2

We can access the time date of a specific date.

        var date = new Date('February 23, 12 17:15');
        console.log(date.getHours());

output:

17


Example 3

        var date = new Date('November 10,10 09:05:00');
        console.log(date.getHours());

output:

9


Browser Support

Chromeyes
Edgeyes
Firefox1
Internet Exploreryes
Operayes
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: