目录

getDay()

描述 (Description)

getDay()方法根据本地时间返回指定日期的星期几。 getDay()返回的值是一个对应于星期几的整数:0表示星期日,1表示星期一,2表示星期二,依此类推。

语法 (Syntax)

下面给出了getDay()方法的语法。

Date.getDay()

例子 (Example)

以下示例演示了CoffeeScript中getDay()方法的用法。 将此代码保存在名为date_getday.coffee的文件中。

dt = new Date "February 19, 2016 23:15:00"
console.log "The day of the current date object is : " + dt.getDay() 

打开command prompt并编译.coffee文件,如下所示。

c:\> coffee -c date_getday.coffee

在编译时,它为您提供以下JavaScript。

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;
  dt = new Date("February 19, 2016 23:15:00");
  console.log("The day of the current date object is : " + dt.getDay());
}).call(this);

现在,再次打开command prompt ,然后运行CoffeeScript文件,如下所示。

c:\> coffee date_getday.coffee

执行时,CoffeeScript文件生成以下输出。

The day in the current date object is : 5
↑回到顶部↑
WIKI教程 @2018