目录

getUTCMonth()

描述 (Description)

getUTCMonth()方法根据通用时间返回指定日期的月份。 getUTCMonth()返回的值是0到11之间的整数,对应于月份。 1月为0,2月为1,3月为2,依此类推。

语法 (Syntax)

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

Date.getUTCMonth()

例子 (Example)

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

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

打开command prompt并编译.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);

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

c:\> coffee date_getutcmonth.coffee

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

The UTC month in the specified date is : 1
↑回到顶部↑
WIKI教程 @2018