當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


CoffeeScript Date getFullYear()用法及代碼示例


描述

這個getFullYear()方法根據當地時間返回指定日期的年份。返回的值getFullYear()是一個絕對數。對於 1000 年和 9999 年之間的日期,getFullYear() 返回 four-digit 數字,例如 2008。

用法

下麵給出的是getFullYear()方法。

getFullYear()

示例

下麵的例子演示了getFullYear()CoffeeScript 中的方法。將此代碼保存在具有名稱的文件中date_getfullyear.coffee

dt = new Date "February 19, 2016 23:15:00"
console.log "The year the current date object is:" + dt.getFullYear()

打開command prompt並編譯 .coffee 文件,如下所示。

c:\> coffee -c date_getfullyear.coffee

在編譯時,它會為您提供以下 JavaScript。

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

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

  console.log("The year the current date object is:" + dt.getFullYear());

}).call(this);

現在,打開command prompt再次運行 CoffeeScript 文件,如下所示。

c:\> coffee date_getfullyear.coffee

在執行時,CoffeeScript 文件產生以下輸出。

The year the current date object is:2016

相關用法


注:本文由純淨天空篩選整理自 CoffeeScript Date - getFullYear()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。