
- CoffeeScript教程
- CoffeeScript-主頁
- CoffeeScript-概述
- CoffeeScript-環境
- CoffeeScript-命令列實用工具
- CoffeeScript-語法
- CoffeeScript-資料型別
- CoffeeScript-變數
- CoffeeScript-運算子和別名
- CoffeeScript-條件
- CoffeeScript-迴圈
- CoffeeScript-解析
- CoffeeScript-函式
- 面向物件CoffeeScript
- CoffeeScript-字串
- CoffeeScript-陣列
- CoffeeScript-物件
- CoffeeScript-範圍
- CoffeeScript-Splat
- CoffeeScript-日期
- CoffeeScript-數學
- CoffeeScript-異常處理
- CoffeeScript-正則表示式
- CoffeeScript-類和繼承
- CoffeeScript高階
- CoffeeScript-Ajax
- CoffeeScript-jQuery
- CoffeeScript-MongoDB
- CoffeeScript-SQLite
- CoffeeScript有用資源
- CoffeeScript-快速指南
- CoffeeScript-有用資源
- CoffeeScript-論壇
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
廣告