Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Date 實例的 getDay() 方法會根據本地時間回傳指定日期的星期幾,其中 0 代表星期日。若要取得月份中的日期,請參見 Date.prototype.getDate()。
無。
一個介於 0 到 6 之間的整數,根據本地時間表示給定日期的星期幾:0 代表星期日,1 代表星期一,2 代表星期二,依此類推。如果日期為無效,則回傳 NaN。
getDay() 的回傳值是從零開始的,這對於索引星期陣列很有用,例如:
然而,為了國際化,你應該優先使用帶有 options 參數的 Intl.DateTimeFormat。
weekday 變數的值為 1,這是基於 Date 物件 xmas95 的值,因為 1995 年 12 月 25 日是星期一。
| ECMAScript® 2027 Language Specification # sec-date.prototype.getday |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月5日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.