From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/date/setdate/index.html | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/date/setdate/index.html (limited to 'files/ja/web/javascript/reference/global_objects/date/setdate') diff --git a/files/ja/web/javascript/reference/global_objects/date/setdate/index.html b/files/ja/web/javascript/reference/global_objects/date/setdate/index.html new file mode 100644 index 0000000000..9042106ce6 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/date/setdate/index.html @@ -0,0 +1,82 @@ +--- +title: Date.prototype.setDate() +slug: Web/JavaScript/Reference/Global_Objects/Date/setDate +tags: + - Date + - JavaScript + - Method + - Prototype + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Date/setDate +--- +
{{JSRef}}
+ +

setDate() メソッドは、現在設定されている月から始まる {{jsxref("Date")}} オブジェクトの「日」を設定します。

+ +
{{EmbedInteractiveExample("pages/js/date-setdate.html")}}
+ + + +

構文

+ +
dateObj.setDate(dayValue)
+ +

引数

+ +
+
dayValue
+
「日」を表す整数の値です。
+
+ +

返値

+ +

協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 から与えられた日付までの間のミリ秒単位の数値 ({{jsxref("Date")}} オブジェクトも適切に変更されます)。

+ +

解説

+ +

dayValue がその月の日付の範囲外の値の場合、それに応じて setDate() が {{jsxref("Date")}} オブジェクトを更新します。

+ +

例えば、dayValue に 0 を与えた場合、日付は前月の最終日に設定されます。

+ +

dayValue に負の数を指定すると、前月の最終日から逆算して日付が設定されます。 -1の場合、日付は前月の最終日の1日前に設定されます。

+ +

+ +

setDate() の使用

+ +
var theBigDay = new Date(1962, 6, 7); // 1962-07-07 (7th of July 1962)
+theBigDay.setDate(24);  // 1962-07-24 (24th of July 1962)
+theBigDay.setDate(32);  // 1962-08-01 (1st of August 1962)
+theBigDay.setDate(22);  // 1962-08-22 (22th of August 1962)
+theBigDay.setDate(0);   // 1962-07-31 (31th of July 1962)
+theBigDay.setDate(98);  // 1962-10-06 (6th of October 1962)
+theBigDay.setDate(-50); // 1962-08-11 (11th of August 1962)
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-date.prototype.setdate', 'Date.prototype.setDate')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Date.setDate")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf