A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate below:

Date.prototype.setDate() - JavaScript | MDN

Date.prototype.setDate()

Baseline Widely available

setDate() は Date インスタンスのメソッドで、地方時に基づいてこの日時の月内の日を変更します。

試してみましょう
const event = new Date("August 19, 1975 23:15:30");

event.setDate(24);

console.log(event.getDate());
// 予想される結果: 24

event.setDate(32);
// Only 31 days in August!

console.log(event.getDate());
// 予想される結果: 1
構文 引数
dateValue

月内の「日」を表す整数の値です。

返値

その場で Date オブジェクトを変更し、新しいタイムスタンプを返します。 dateValue が NaN (または undefined など、 NaN に変換されるその他の値)の場合、日付は無効な日時に設定され、 NaN が返されます。

解説

指定した数値が指定した範囲外の場合、Date オブジェクトの日付情報がそれに応じて更新されます。例えば、 Date オブジェクトが 6 月 1 日を保持している場合、 dateValue を 40 に変更すると日付は 7 月 10 日になり、 dateValue を 0 に変更すると日付は前月の最終日である 5 月 31 日になります。

例 setDate() の使用
const theBigDay = new Date(1962, 6, 7, 12); // 1962-07-07 正午(月は 0 起点)
const theBigDay2 = new Date(theBigDay).setDate(24); // 1962-07-24
const theBigDay3 = new Date(theBigDay).setDate(32); // 1962-08-01
const theBigDay4 = new Date(theBigDay).setDate(22); // 1962-07-22
const theBigDay5 = new Date(theBigDay).setDate(0); // 1962-06-30
const theBigDay6 = new Date(theBigDay).setDate(98); // 1962-10-06
const theBigDay7 = new Date(theBigDay).setDate(-50); // 1962-05-11
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4