setTime【経過ミリ秒設定 (UTC)】
setUTCFullYear【年月日設定 (UTC)】
setUTCMonth【月日設定 (UTC)】
setUTCDate【日設定 (UTC)】
setUTCHours【時分秒設定 (UTC)】
setUTCMinutes【分秒設定 (UTC)】
setUTCSeconds【秒設定 (UTC)】
setUTCMilliseconds【ミリ秒設定 (UTC)】
Date.prototype.setTime【経過ミリ秒設定 (UTC)】
メモ
概要
- 経過ミリ秒を設定 (1970/01/01 00:00:00 UTC からの経過ミリ秒)
- 一部分を設定 (月だけ等)
- setUTC~【~設定 (UTC)】:メソッド分類 参照
- 取得:getTime【経過ミリ秒取得 (UTC)】
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setTime (time) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setTime( time )
1970/01/01 00:00:00 UTC からの経過ミリ秒
time1970/01/01 00:00:00 UTC からの経過ミリ秒
例
var date = new Date();
console.log(date.setTime(1234));
console.log(date.toString(), date.getMilliseconds()); // 出力:Thu Jan 01 1970 09:00:01 GMT+0900 (東京 (標準時)) 234
date = new Date("2001-02-03 04:05:06.789");
console.log(date.toString(), date.getMilliseconds()); // 出力:Sat Feb 03 2001 04:05:06 GMT+0900 (東京 (標準時)) 789
var time = date.getTime();
console.log(time); // 出力:981140706789
date.setTime(time);
console.log(date.toString(), date.getMilliseconds()); // 出力:Sat Feb 03 2001 04:05:06 GMT+0900 (東京 (標準時)) 789
date.setTime(NaN);
console.log(date.toString(), date.getMilliseconds()); // 出力:Invalid Date NaN
Date.prototype.setUTCFullYear【年月日設定 (UTC)】
メモ
概要
- 年・月・日部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCFullYear (year [, month [, date ] ] ) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCFullYear( year[, month[, date]] )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
yearUTCの年
monthUTCの月 (0~11 / 省略:元の値 / その他:補正)
dateUTCの日 (省略:元の値 / その他:補正)
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCFullYear(2100);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Wed, 03 Feb 2100 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCFullYear(2100, (12 - 1));
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 03 Dec 2100 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCFullYear(2100, (-1));
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Thu, 03 Dec 2099 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCFullYear(2100, (13 -1));
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Mon, 03 Jan 2101 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCFullYear(2100, (12 - 1), 31);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 31 Dec 2100 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCFullYear(2100, (12 - 1), 0);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Tue, 30 Nov 2100 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCFullYear(2100, (12 - 1), 32);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 01 Jan 2101 04:05:06 GMT 789
date = new Date(NaN);
date.setUTCFullYear(2100);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 01 Jan 2100 00:00:00 GMT 0
date = new Date(NaN);
date.setUTCFullYear(2100, (12 - 1));
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Wed, 01 Dec 2100 00:00:00 GMT 0
date = new Date(NaN);
date.setUTCFullYear(2100, (12 - 1), 31);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 31 Dec 2100 00:00:00 GMT 0
Date.prototype.setUTCMonth【月日設定 (UTC)】
メモ
概要
- 月・日部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCMonth (month [, date ] ) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCMonth( month[, date] )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
monthUTCの月 (0~11 / 省略:元の値 / その他:補正)
dateUTCの日 (省略:元の値 / その他:補正)
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCMonth((12 -1));
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Mon, 03 Dec 2001 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMonth((12 -1), 31);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Mon, 31 Dec 2001 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMonth((13-1));
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Thu, 03 Jan 2002 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMonth((12 -1), 0);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 30 Nov 2001 04:05:06 GMT 789
date = new Date(NaN);
console.log(date.setUTCMonth((12 -1))); // 出力:NaN
console.log(date.setUTCMonth((12 -1), 31)); // 出力:NaN
Date.prototype.setUTCDate【日設定 (UTC)】
メモ
概要
- 日部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCDate (date) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCDate( date )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
dateUTCの日 (存在しない日付になる場合、補正)
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCDate(28);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Wed, 28 Feb 2001 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCDate(-1);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Tue, 30 Jan 2001 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCDate(0);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Wed, 31 Jan 2001 04:05:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCDate(29);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Thu, 01 Mar 2001 04:05:06 GMT 789
date = new Date(NaN);
date.setUTCDate(1);
console.log(date.getUTCDate()); // 出力:NaN
Date.prototype.setUTCHours【時分秒設定 (UTC)】
メモ
概要
- 時・分・秒・ミリ秒部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCHours (hour [, min [, sec [, ms ] ] ] ) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCHours( hour[, min[, sec[, ms]]] )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
hourUTCの時 (詳細は下記参照)
minUTCの分 (詳細は下記参照)
secUTCの秒 (詳細は下記参照)
msUTCのミリ秒 (詳細は下記参照)
hour | 説明 |
---|---|
0~23 | 0~23 時 |
その他 | 補正 |
min | 説明 |
---|---|
省略 | 元の値 |
0~59 | 0~59 分 |
その他 | 補正 |
sec | 説明 |
---|---|
省略 | 元の値 |
0~59 | 0~59 秒 |
その他 | 補正 |
ms | 説明 |
---|---|
省略 | 元の値 |
0~999 | 0~999 ミリ秒 |
その他 | 補正 |
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCHours(12);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 12:05:06 GMT 789
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(12, 34);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 02 Feb 2001 12:34:06 GMT 789
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(12, 34, 56);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 02 Feb 2001 12:34:56 GMT 789
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(12, 34, 56, 987);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 02 Feb 2001 12:34:56 GMT 987
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(24);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 00:05:06 GMT 789
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(12, 60);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 02 Feb 2001 13:00:06 GMT 789
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(12, 34, 60);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 02 Feb 2001 12:35:00 GMT 789
date = new Date("2001-02-03 04:05:06.789");
date.setUTCHours(12, 34, 56, 1234);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Fri, 02 Feb 2001 12:34:57 GMT 234
date = new Date(NaN);
console.log(date.setUTCHours(12)); // 出力:NaN
console.log(date.setUTCHours(12, 34)); // 出力:NaN
console.log(date.setUTCHours(12, 34, 56)); // 出力:NaN
console.log(date.setUTCHours(12, 34, 56, 987)); // 出力:NaN
Date.prototype.setUTCMinutes【分秒設定 (UTC)】
メモ
概要
- 分・秒・ミリ秒部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCMinutes (min [, sec [, ms ] ] ) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCMinutes( min[, sec[, ms]] )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
minUTCの分 (詳細は下記参照)
secUTCの秒 (詳細は下記参照)
msUTCのミリ秒 (詳細は下記参照)
min | 説明 |
---|---|
省略 | 元の値 |
0~59 | 0~59 分 |
その他 | 補正 |
sec | 説明 |
---|---|
省略 | 元の値 |
0~59 | 0~59 秒 |
その他 | 補正 |
ms | 説明 |
---|---|
省略 | 元の値 |
0~999 | 0~999 ミリ秒 |
その他 | 補正 |
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCMinutes(22);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:22:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMinutes(22, 33);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:22:33 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMinutes(22, 33, 444);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:22:33 GMT 444
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMinutes(60);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 05:00:06 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMinutes(22, 60);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:23:00 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMinutes(22, 33, 1234);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:22:34 GMT 234
date = new Date(NaN);
console.log(date.setUTCMinutes(22)); // 出力:NaN
console.log(date.setUTCMinutes(22, 33)); // 出力:NaN
console.log(date.setUTCMinutes(22, 33, 444)); // 出力:NaN
Date.prototype.setUTCSeconds【秒設定 (UTC)】
メモ
概要
- 秒・ミリ秒部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCSeconds (sec [, ms ] ) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCSeconds( sec[, ms] )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
secUTCの秒
msUTCのミリ秒
sec | 説明 |
---|---|
省略 | 元の値 |
0~59 | 0~59 秒 |
その他 | 補正 |
ms | 説明 |
---|---|
省略 | 元の値 |
0~999 | 0~999 ミリ秒 |
その他 | 補正 |
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCSeconds(16);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:16 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCSeconds(16, 987);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:16 GMT 987
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCSeconds(60);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:06:00 GMT 789
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCSeconds(16, 1234);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:17 GMT 234
date = new Date(NaN);
console.log(date.setUTCSeconds(16)); // 出力:NaN
console.log(date.setUTCSeconds(16, 987)); // 出力:NaN
Date.prototype.setUTCMilliseconds【ミリ秒設定 (UTC)】
メモ
概要
- ミリ秒部分の設定 (UTC)
関連
外部リンク
- ECMA-262 (英語)
Date.prototype.setUTCMilliseconds (ms) ES2024 (15) ES2023 (14) ES2022 (13)
構文
date.setUTCMilliseconds( ms )
設定後の1970/01/01 00:00:00 UTC からの経過ミリ秒
msUTCのミリ秒 (省略:元の値 / その他:補正)
例
var date = new Date("2001-02-03Z04:05:06.789");
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 789
date.setUTCMilliseconds(987);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:06 GMT 987
date = new Date("2001-02-03Z04:05:06.789");
date.setUTCMilliseconds(1234);
console.log(date.toUTCString(), date.getUTCMilliseconds()); // 出力:Sat, 03 Feb 2001 04:05:07 GMT 234
date = new Date(NaN);
console.log(date.setUTCMilliseconds(987)); // 出力:NaN