Date.prototype.getDay()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

getDay() メソッドは、地方時に基づき、指定された日付の曜日を返します。 0 は日曜日を表します。「日」を取得する方法は Date.prototype.getDate() をご覧ください。

試してみましょう

const birthday = new Date("August 19, 1975 23:15:30");
const day1 = birthday.getDay();
// Sunday - Saturday : 0 - 6

console.log(day1);
// Expected output: 2

構文

js
getDay()

返値

整数値で、 0 から 6 までの値を取り、地方時に基づいて指定された日付の曜日に対応し、 0 は日曜日、 1 は月曜日、 2 は火曜日のようになります。

getDay の使用

以下の 2 行目の文は、 Date オブジェクトである xmas95 の値に基づき、weekday に 1 という値を代入します。1995 年 12 月 25 日は月曜日です。

js
const xmas95 = new Date("December 25, 1995 23:15:30");
const weekday = xmas95.getDay();

console.log(weekday); // 1

メモ: 必要であれば、曜日の完全な名前 (例えば "Monday") は Intl.DateTimeFormatoptions 引数を設定することで取得することができます。このメソッドを使用すれば、国際化がより簡単になります。

js
const options = { weekday: "long" };
console.log(new Intl.DateTimeFormat("en-US", options).format(Xmas95));
// Monday
console.log(new Intl.DateTimeFormat("de-DE", options).format(Xmas95));
// Montag

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-date.prototype.getday

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
getDay

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報