setHours

Commons
stable

Return a new Date with the hours field replaced by the given count. The original date is never mutated.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

date
required
Date
The source date. It is cloned before the hours field is updated.
count
required
number
The hours value to set (0–23).

API

Return value

The value returned by this util.

A new Date object with the specified hours field.

Usage

Examples

Ready-to-paste usage snippets.

Set the hour on a date

typescript