---
description: Returns the hour (from 0-23)
---

# Date.getHours()

The getHours() method returns the hour for the specified date, according to local time.

```javascript
var birthday = new Date('March 13, 08 04:20');

console.log(birthday.getHours());
// expected output: 4

```

## Syntax <a href="#syntax" id="syntax"></a>

```javascript
dateObj.getHours()
```

**Return value**&#x20;

An integer number, between 0 and 23, representing the hour for the given date according to local time.

## Description <a href="#examples" id="examples"></a>

The value returned by `getFullYear()` is an absolute number. For dates between the years 1000 and 9999, `getFullYear()` returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000.

## Examples <a href="#examples" id="examples"></a>

#### Using `getHours()` <a href="#using_gethours" id="using_gethours"></a>

The second statement below assigns the value 23 to the variable `hours`, based on the value of the [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object `Xmas95`.

```javascript
var Xmas95 = new Date('December 25, 1995 23:15:30');
var hours = Xmas95.getHours();

console.log(hours); // 23
```

## References <a href="#references" id="references"></a>

{% embed url="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours" %}

## Contributors to this page <a href="#contributors-to-this-page" id="contributors-to-this-page"></a>

Uros Durdevic\
