LoginSignup
0
2

More than 3 years have passed since last update.

JavaScript で日本標準時の Date オブジェクトを生成する

Posted at

以下のコードで日本標準時の Date オブジェクトが生成される。

const date = new Date("2019-10-30T19:04:22+09:00");
console.log(date); // Wed Oct 30 2019 19:04:22 GMT+0900 (日本標準時)

解説

  1. "2019-10-30T19:04:22+09:00"ISO 8601 の拡張形式
  2. new Date(dateString) -> Date - JavaScript | MDN 参照

ちなみに、ISO 8601 の基本形式で記述すると、

const date = new Date("20191030T190422+0900");
console.log(date); // Invalid Date

まとめ

JavaScript でタイムゾーンを含めた時刻を扱うときは、ISO 8601 の拡張形式で記述する。

0
2
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
0
2