Convert Dates Between Time Zones – minitz.js

Category: Date & Time , Javascript | September 24, 2022
Author:Hexagon
Views Total:0 views
Official Page:Go to website
Last Update:September 24, 2022
License:MIT

Preview:

Convert Dates Between Time Zones – minitz.js

Description:

A lightweight JavaScript utility script that allows you to transform any date into another timezone and vice versa.

This means you can use this script to format and parse dates using timezones. Works in Node.js, Deno, and modern browsers.

How to use it:

1. Install and download.

# NPM
$ npm i minitz

2. Import the minitz.js.

// ES
import minitz from "minitz";
// CommonJS
const minitz = require("minitz");
// Browser
<script src="./dist/minitz.min.js"></script>
// CDN
<script src="https://cdn.jsdelivr.net/npm/minitz/dist/minitz.min.js"></script>

3. Convert the date to another time zone.

timeInNewYork = minitz.toTZ(new Date(), "America/New_York");

4. Convert the date to local time zone.

const localTime =  minitz(y,m,d,h,i,s, "Canada/Mountain");
// use ISO8601 strings
const localTime = minitz.fromTZISO("2022-09-15 23:00:00", "Canada/Mountain");

5. It also allows creating faux dates from TimePoint.

minitz.fauxDate(timeInNewYork)

Changelog:

v3.0.0 (09/24/2022)

  • breaking: Stop exporting non minified cjs to npm
  • fix: Use Date.parse instead of custom ISO8601 parsing function

v2.1.1 (09/17/2022)

  • Bugfix

v2.1.0 (09/15/2022)

  • Code cleanup
  • Add .toTZISO(…) for using ISO8601 formatted time string

v2.0.0 (09/14/2022)

  • Add shortcut to convert from a specific timezone to local minitz(y,m,d,h,i,s,tz);
  • Introduce TimePoint object instead of faux dates
  • Allow creating faux dates from TimePoint using new function minitz.fauxDate()

You Might Be Interested In:


Leave a Reply