tiempo

addHours

Add hours to a datetime

Add hours to a datetime.

Signature

function addHours(
  input: Temporal.Instant | Temporal.ZonedDateTime,
  hours: number
): Temporal.ZonedDateTime

Parameters

ParameterTypeDescription
inputTemporal.Instant | Temporal.ZonedDateTimeThe datetime to add hours to
hoursnumberNumber of hours to add (can be negative)

Returns

A Temporal.ZonedDateTime with the hours added.

Examples

import { addHours } from '@gobrand/tiempo';

const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
addHours(instant, 3);
// 2025-01-20T15:00:00Z[UTC]

addHours(instant, -5);
// 2025-01-20T07:00:00Z[UTC]

On this page