CoffeeScript日期-getHours()



說明

gethours()方法返回根據本地時間在指定日期中的小時。getHours()返回的值為介於0和23之間的整數。

語法

以下是gethours()方法的語法。

getHours()

示例

以下示例演示了在CoffeeScript中使用getHours()方法。將此程式碼儲存在名為date_gethours.coffee的檔案中。

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

開啟命令提示符並如下所示編譯.coffee檔案。

c:\> coffee -c date_gethours.coffee

編譯時,將得到以下JavaScript。

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

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

  console.log("The hour value in the current date object is : " + dt.getHours());

}).call(this);

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

c:\> coffee date_gethours.coffee

執行時,CoffeeScript檔案產生以下輸出。

The hour value in the current date object is : 23
coffeescript_date.htm
廣告