Skip to content

Instantly share code, notes, and snippets.

@devwolf75
devwolf75 / toTimezone.ts
Created February 14, 2020 04:24
Typescript function that takes a Date, string or moment object and converts it between timezones.
import * as moment from "moment-timezone";
/**
* @description
* @param {Date | string | moment} date Date to transform.
* @param {string} originTZ Timezone in which the date to transform is currently. I.E. "UTC". Defaults to client PC TZ.
* @param {string} destinationTZ Timezone to which to convert the date. I.E. "America/Los Angeles". Defaults to "UTC".
* @return {string} Date converted to destination timezone in string.
*
*/