当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


CoffeeScript Date getUTCFullYear()用法及代码示例



描述

这个getUTCFullYear()方法根据通用时间返回指定日期中的年份。 getUTCFullYear() 返回的值是一个符合年份-2000 的绝对数,例如2008。

用法

下面给出的是getUTCFullYear()方法。

Date.getUTCFullYear()

示例

下面的例子演示了getUTCFullYear()CoffeeScript 中的方法。将此代码保存在具有名称的文件中date_getutcfullyear.coffee

dt = new Date "February 19, 2016 23:15:25:22"
console.log "The UTC full year in the specified date is:" + dt.getFullYear()

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

c:\> coffee -c date_getutcfullyear.coffee

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

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

  dt = new Date("February 19, 2016 23:15:25:22");

  console.log("The UTC full year in the specified date is:" + dt.getFullYear());

}).call(this);

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

c:\> coffee date_getutcfullyear.coffee

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

The UTC full year in the specified date is:2016

相关用法


注:本文由纯净天空筛选整理自 CoffeeScript Date - getUTCFullYear()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。