目录

setUTCFullYear()

描述 (Description)

setUTCFullYear()方法根据通用时间设置指定日期的全年。

语法 (Syntax)

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

Date.setUTCFullYear(yearValue[, monthValue[, dayValue]])

参数细节 (Parameter Detail)

  • yearValue - 指定年份数值的整数,例如,2008。

  • monthValue - 0到11之间的整数,表示1月到12月的月份。

  • dayValue - 1到31之间的整数,表示该月的某天。 如果指定dayValue参数,则还必须指定monthValue。

如果未指定monthValue和dayValue参数,则使用从getMonth和getDate方法返回的值。 如果指定的参数超出预期范围,则setUTCFullYear会尝试相应地更新Date对象中的其他参数和日期信息。 例如,如果为monthValue指定15,则年份增加1(年+ 1),并且3用于月份。

例子 (Example)

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

dt = new Date "February 19, 2016 23:15:00"
dt.setUTCFullYear 20 
console.log dt

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

c:\> coffee -c date_setutcfullYear.coffee

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

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;
  dt = new Date("February 19, 2016 23:15:00");
  dt.setUTCFullYear(20);
  console.log(dt);
}).call(this);

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

c:\> coffee date_setutcfullYear.coffee

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

Wed Feb 19 20 23:15:00 GMT+0530 (India Standard Time)
↑回到顶部↑
WIKI教程 @2018