UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

19 lines (18 loc) 631 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTimezoneOffsetString = void 0; /** * Returns timezone offset formatted as +HH:mm or -HH:mm. * @author @dailker * @param {Date} date * @returns {string} */ function getTimezoneOffsetString(date) { const offset = -date.getTimezoneOffset(); const sign = offset >= 0 ? '+' : '-'; const abs = Math.abs(offset); const h = String(Math.floor(abs / 60)).padStart(2, '0'); const m = String(abs % 60).padStart(2, '0'); return `${sign}${h}:${m}`; } exports.getTimezoneOffsetString = getTimezoneOffsetString;