38
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

昨日の日付がこんなに簡単に・・・。

Last updated at Posted at 2015-12-08
var now = new Date();
var yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);

って書くと、

console.log(now);       // Thu Jul 01 2021 07:08:25 GMT+0900 (日本標準時)
console.log(yesterday); // Wed Jun 30 2021 00:00:00 GMT+0900 (日本標準時)

こうなる・・・。

ずーーーーーっと、日付だけマイナス1されて、月はそのままだと思ってました。
(でもなんか違和感があるなぁー)

覚えようっと♪

38
22
2

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
38
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?