From a329d01ae339a87a8670f28bdb4a5595a8a7cad9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 9 Mar 2022 23:29:07 -0700 Subject: [PATCH] feat: add toLocalISOString() --- README.md | 8 ++++++++ index.html | 15 ++++++++++++++ tolocalisostring.js | 50 +++++++++++++++++++++++++++++++++++++++++++++ xtz.js | 28 ++++++++++++++++++++++--- 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 tolocalisostring.js diff --git a/README.md b/README.md index ea07a0f..d385046 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,13 @@ in ~100 LoC. For Node.js & Browsers. XTZ is a poor man's `Temporal` polyfill, but just for time zones. \ Demo: +```js +// What's the current time, in ISO format? + +TZ.toLocalISOString(new Date()); // "2021-11-07T03:15:59.000-0500" +TZ.timeZone(); // "America/New_York" +``` + > What UTC time will it be when it's 3:15am in New York? ```js @@ -89,6 +96,7 @@ See . # API +- `toLocalISOString(dateOrNull)` - `toTimeZone(utcDate, timeZone)` - `toTimeZoneISOString(isoString, timeZone)` - `toUTC(dtString, timeZone)` diff --git a/index.html b/index.html index 577417e..ecb441f 100644 --- a/index.html +++ b/index.html @@ -83,6 +83,18 @@
+
+

Local ISO+Offset String:

+
XTZ.toLocalISOString(new Date())
+ +
+
+ +
+

Relative TimeZone to Absolute UTC:

XTZ.toUTC("YYYY-03-14 03:15:69.000", "UTC")
@@ -179,6 +191,7 @@ Asia/Kolkata        +0530 (No DST) (30-min)
github.com/therootcompany/tz.js +