Date.prototype.setDate()
setDate()
メソッドは、現在設定されている月から始まる Date
オブジェクトの「日」を設定します。
指定された日時の月日を UTC 時間に基づいて変更するには、代わりに setUTCDate()
メソッドを使用してください。
試してみましょう
構文
js
setDate(dayValue)
引数
dayValue
-
「日」を表す整数の値です。
返値
協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 から与えられた日付までの間のミリ秒単位の数値(Date
オブジェクトも適切に変更されます)。
解説
例
setDate() の使用
js
const theBigDay = new Date(1962, 6, 7, 12); // noon of 1962-07-07 (7th of July 1962, month is 0-indexed)
const theBigDay2 = new Date(theBigDay).setDate(24); // 1962-07-24 (24th of July 1962)
const theBigDay3 = new Date(theBigDay).setDate(32); // 1962-08-01 (1st of August 1962)
const theBigDay4 = new Date(theBigDay).setDate(22); // 1962-07-22 (22nd of July 1962)
const theBigDay5 = new Date(theBigDay).setDate(0); // 1962-06-30 (30th of June 1962)
const theBigDay6 = new Date(theBigDay).setDate(98); // 1962-10-06 (6th of October 1962)
const theBigDay7 = new Date(theBigDay).setDate(-50); // 1962-05-11 (11th of May 1962)
仕様書
Specification |
---|
ECMAScript Language Specification # sec-date.prototype.setdate |
ブラウザーの互換性
BCD tables only load in the browser