From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../global_objects/date/getday/index.html | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html (limited to 'files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html') diff --git a/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html b/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html new file mode 100644 index 0000000000..abdc0e89a1 --- /dev/null +++ b/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html @@ -0,0 +1,72 @@ +--- +title: Date.prototype.getDay() +slug: Web/JavaScript/Reference/Global_Objects/Date/getDay +translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay +--- +
{{JSRef}}
+ +

getDay() 方法會根據當地時間將指定日期返回一星期中的第幾天,其中0代表星期日。 在當月的某天可以參考{{jsxref("Date.prototype.getDate()")}}。

+ +
{{EmbedInteractiveExample("pages/js/date-getday.html", "shorter")}}
+ + + +

語法

+ +
dateObj.getDay()
+ +

返回值

+ +

返回一個整數,數值介於0到6之間,取決於當地時間對應出指定日期為星期幾:0代表星期日,1代表星期一,2代表星期二,依此類推。

+ +

範例

+ +

使用 getDay()

+ +

下面第二行表示根據日期對象'Xmas95'的值,把1賦值給'weekday'。則1995年12月25日是星期一。

+ +
var Xmas95 = new Date('December 25, 1995 23:15:30');
+var weekday = Xmas95.getDay();
+
+console.log(weekday); // 1
+
+ +
+

Note: 如果需要,可以使用{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}加上options參數來獲取星期幾全名。使使用此方法能輕鬆做出各種國際語言:

+ +
var 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
{{SpecName('ESDraft', '#sec-date.prototype.getday', 'Date.prototype.getDay')}}
+ +

瀏覽器兼容性

+ + + +

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

+ +

See also

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