LoginSignup
1
1

More than 3 years have passed since last update.

JavaScriptでタイムゾーン付きの文字列(ISO8601)をJSTの"yyyy/mm/dd HH24:mi:ss"で表示する

Posted at

概要

タイムゾーン付きの文字列(ISO8601)をJSTで表示する。

実装

a = new Date('2020-03-09T19:21:13+09:00')
// Mon Mar 09 2020 19:21:13 GMT+0900 (日本標準時)
a.toLocaleDateString("ja-JP", {timeZone: "Asia/Tokyo"})
// "2020/3/9"
a.toLocaleString("ja-JP", {timeZone: "Asia/Tokyo"})
// "2020/3/9 19:21:13"
a.toLocaleString("ja-JP", {timeZone: "America/New_York"})
// "2020/3/9 6:21:13"

おまけ

月日を0パディングしたい場合は、

a = new Date('2020-03-09T19:21:13+09:00')
a.toLocaleDateString("ja-JP", {timeZone: "Asia/Tokyo", year: "numeric", month: "2-digit", day: "2-digit"})
// "2020/03/09"

※参考
* options部分(timeZone指定している部分)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1