Time Zones And UTC Converter In JavaScript – xtz.js

Category: Date & Time , Javascript | March 12, 2022
Author:therootcompany
Views Total:77 views
Official Page:Go to website
Last Update:March 12, 2022
License:MIT

Preview:

Time Zones And UTC Converter In JavaScript – xtz.js

Description:

xtz.js is a lightweight, blazing-fast JavaScript library for converting between time zones as well as translating between Relative TimeZone and Absolute UTC.

How to use it:

1. Insert the JavaScript xtz.js into the HTML document.

<script src="./xtz.js"></script>

2. Initialize.

var XTZ = window.XTZ;

3. Convert Relative TimeZone to Absolute UTC.

// toUTC(dtString, timeZone)
XTZ.toUTC("2021-06-03 12:52:46.007", "Asia/Shanghai")
   .toISOString()
// => 2021-06-03T12:52:46.007+0800
// OR 
// toUTCISOString(dtString, timeZone)
XTZ.toUTCISOString("2021-06-03 12:52:46.007", "Asia/Shanghai")
// => 2021-06-03T12:52:46.007+0800

4. Convert Absolute UTC to Relative TimeZone.

// toTimeZone(utcDate, timeZone)
XTZ.toTimeZone("2021-06-03T04:50:36.715Z", "Asia/Shanghai")
  .toISOString()
// => 2021-06-03T12:50:36.715+0800
// OR 
// toTimeZoneISOString(isoString, timeZone)
XTZ.toTimeZoneISOString("2021-06-03T04:50:36.715Z", "Asia/Shanghai")
// => 2021-06-03T12:50:36.715+0800

Changelog:

v1.3.2 (03/12/2022)

  • fix: add timeZone() and fix toOffsetISOString()

You Might Be Interested In:


Leave a Reply