Temporal : JSの新しいDate Time API
(2ality.com)-
既存のJavaScriptの日付/時刻APIは非常に使いにくいため、新たに提案されているAPI : 現在 Stage 3
-
グローバル変数である Temporal を通じてアクセス可能
→ すべてのオブジェクトは Immutable
→ タイムゾーン(IANAベース)および非グレゴリオ暦をサポート(韓国の檀紀を含む)
→ 1月は Month 1
→ Wall-Clock(ローカル)時間 と Exact(UTC)時間 を区別
→ タイムゾーンなしの Plain 時間をサポート
- 例
→ 現在のUTC時刻 : Temporal.now.instant().toString()
→ 現在のローカル時刻 : Temporal.now.zonedDateTimeISO('Asia/Seoul').toString()
→ 現在のタイムゾーン : Temporal.now.timeZone().toString()
→ Temporal.Duration.from({hours: 3, minutes: 45})
→ 既存の Date と変換
const legacyDate = new Date('1970-01-01T00:00:01Z')
legacyDate.toTemporalInstant() または Temporal.Instant.fromEpochMilliseconds(legacyDate.getTime())
まだコメントはありません。