Skip to content

adjustTimezone

The adjustTimezone function adjusts a date to a target timezone, returning a new Date instance.

Syntax

typescript
adjustTimezone(date: Date, targetTimezone: number): Date;

Parameters

NameTypeDescription
dateDateThe date to be adjusted
targetTimezonenumberThe target timezone (in hours, e.g., -3 for GMT-3)

Returns

TypeDescription
DateDate instance adjusted to timezone

Examples

typescript
adjustTimezone(new Date("2024-06-10T12:00:00Z"), -3);
// => Date Mon Jun 10 2024 09:00:00 GMT-0300

Notes

  • Throws an error if the date is not valid.
  • Useful for converting dates between different timezones.

References

Released under the MIT License.