JavaScript getDay() 方法
页面下方有更多实例。
定义和用法
getDay()
方法返回指定日期是星期几(从 0 到 6)。
注释: 星期日为 0,星期一为 1,依此类推。
浏览器支持
方法 | |||||
---|---|---|---|---|---|
getDay() | Yes | Yes | Yes | Yes | Yes |
语法
Date.getDay()
参数
None |
技术细节
返回值: | 数值,从 0 到 6,表示星期几。 |
---|---|
JavaScript 版本: | ECMAScript 1 |
更多实例
实例
返回周名(不仅仅是数字):
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
亲自试一试 »
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
相关页面
JavaScript 教程: JavaScript 日期
JavaScript 教程: JavaScript 日期格式
JavaScript 教程: JavaScript Date Get Methods