LoginSignup
13
8

More than 5 years have passed since last update.

JavaScriptで昨日の日付を取得する

Posted at

自動的に、
その日の昨日の日付を取得し、
その後年月日を切り離して使用したい時。

今日を取得して年月日を切り離して使用する場合

var objDate = new Date(),
    year    = objDate.getFullYear(),
    month   = objDate.getMonth()+ 1,
    day     = objDate.getDate();

昨日を取得して年月日を切り離して使用する場合

var objDate = new Date();

objDate.setDate(objDate.getDate() - 1);

var year    = objDate.getFullYear(),
    month   = objDate.getMonth()+ 1,
    day     = objDate.getDate();
13
8
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
13
8