[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay [Back]  [Original]

Date.prototype.getDay() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Date.prototype.getDay()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.

Date getDay() 0 Date.prototype.getDate()

In this article

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

console.log(day1);
// 2

js
getDay()

0 6 0 1 2 NaN

getDay()

js
const valentines = new Date("1995-02-14");
const day = valentines.getDay();
const dayNames = ["", "", "" /* ,  */];

console.log(dayNames[day]); // ""

options Intl.DateTimeFormat

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

getDay()

weekday 1 Date xmas95 1995 12 25

js
const xmas95 = new Date("1995-12-25T23:15:30");
const weekday = xmas95.getDay();

console.log(weekday); // 1

Specification
ECMAScript 2027 LanguageSpecification
# sec-date.prototype.getday


Web Proxy Viewer  |  New URL  |  Original Page