const ISO8601 = '2022-05-19T17:00:00+09:00';
const hourMinutes = new Date(ISO8601)
// ロケールを日本に指定
// 「言語コード-国コード」形式の引数とtimeZoneの指定
// → 2022/5/19 17:00:00
.toLocaleString('ja-JP', { timeZone: 'Asia/Tokyo' })
// スペースで日付と時間を区切る
// → ['2022/5/19', '17:00:00']
.split(' ')[1]
// 「時間:分:秒」形式の文字列から後ろの「:秒」を削除する
// → 17:00
.slice(0,-3);
console.log(hourMinutes); // 17:00
Created
May 18, 2022 23:51
-
-
Save LeeDDHH/ce5f53e15ccafe4cb39a2575b1fbc8bd to your computer and use it in GitHub Desktop.
javascriptでDateオブジェクトを扱うためのあれこれ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment