Time Zones And UTC Converter In JavaScript – xtz.js

Category: Date & Time , Javascript | June 15, 2021
Author:therootcompany
Views Total:27 views
Official Page:Go to website
Last Update:June 15, 2021
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

You Might Be Interested In:


Leave a Reply