CoffeeScript 日期 - getUTCMonth()



描述

getUTCMonth() 方法根据世界标准时间返回指定日期中的月份。getUTCMonth() 返回的值是 0 到 11 之间的一个整数,对应于月份。0 代表 1 月,1 代表 2 月,2 代表 3 月,依此类推。

语法

以下是 getUTCMonth() 方法的语法。

Date.getUTCMonth()

示例

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

dt = new Date()
console.log "The UTC month in the specified date is : " + dt.getUTCMonth()

打开 命令提示符,并编译 .coffee 文件,如下所示。

c:\> coffee -c date_getutcmonth.coffee 

编译后,它会提供以下 JavaScript。

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;

  dt = new Date();

  console.log("The UTC month in the specified date is : " + dt.getUTCMonth());

}).call(this);

现在,再次打开 命令提示符,并运行 CoffeeScript 文件,如下所示。

c:\> coffee date_getutcmonth.coffee

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

The UTC month in the specified date is : 1
coffeescript_date.htm
广告
© . All rights reserved.