CoffeeScript 日期 - getUTCFullYear()



描述

getUTCFullYear() 方法根據世界時返回指定日期中的年份。getUTCFullYear() 返回的值是一個絕對數字,與 2000 年後的標準一致,例如 2008。

語法

下面是 getUTCFullYear() 方法的語法。

Date.getUTCFullYear()

示例

以下示例演示了 CoffeeScript 中 getUTCFullYear() 方法的用法。將此程式碼儲存在名為 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()

開啟 命令提示符 並編譯 .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);

現在,再次開啟 命令提示符,並執行 CoffeeScript 檔案,如下所示。

c:\> coffee date_getutcfullyear.coffee

在執行 CoffeeScript 檔案時,會生成以下輸出。

The UTC full year in the specified date is : 2016
coffeescript_date.htm
廣告
© . All rights reserved.