LoginSignup
0
1

More than 3 years have passed since last update.

JavaScript Dateオブジェクトの罠について

Posted at

Dateオブジェクトの罠について

年月日指定でオブジェクトを生成する時、区切り文字によって時刻が異なる

ハイフン区切りの場合

var date = new Date('2020-07-01');
console.log(date);
// => Wed Jul 01 2020 09:00:00 GMT+0900 (日本標準時)

スラッシュ区切りの場合

var date = new Date('2020/07/01');
console.log(date);
// => Wed Jul 01 2020 00:00:00 GMT+0900 (日本標準時)
  • ハイフン区切りの場合では、指定年月日の09:00:00を返すが、スラッシュ区切りの場合では、指定年月日の00:00:00を返す
0
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
0
1