What is Temporal
A global Object that acts as a top-level namespace (like Math), that brings a modern date/time API to the ECMAScript language.
It is on Stage 3 proposal at the time of publishing this article.
Time-zone conversion
What I would like to show you in this article is one of the killer methods that should be super useful, Time-zone conversion๐บ.
(Plus, it does support DST-safe arithmetic!! ๐คฏ)
const instant = Temporal.Instant.from('2022-02-27T02:04Z');
instant.toString(); // => '2022-02-27T02:04:00Z'
const currentTz = Temporal.Now.timeZone();
currentTz.toString(); // => 'Asia/Tokyo'
const jpDateTime = new Temporal.ZonedDateTime(
instant.epochNanoseconds,
currentTz,
Temporal.Calendar.from('iso8601')
);
jpDateTime.toString();
// => '2022-02-27T11:04:00+09:00[Asia/Tokyo]'
const laDateTime = new Temporal.ZonedDateTime(
instant.epochNanoseconds,
Temporal.TimeZone.from('America/Los_Angeles'),
Temporal.Calendar.from('iso8601')
);
laDateTime.toString()
// => '2022-02-26T18:04:00-08:00[America/Los_Angeles]'
How I tried Temporal
Open this official doc and used the dev-tool console ๐ฎ
Reference
For more details, please check out the official documents ๐
Oldest comments (0)