CoffeeScript 日期 - getSeconds()



描述

getSeconds() 方法返回根據本地時間指定的日期的秒數。getSeconds() 返回的值是一個介於 0 和 59 之間的整數。

語法

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

Date.getSeconds()

示例

以下示例展示了 CoffeeScript 中 getSeconds() 方法的用法。將此程式碼儲存在一個名為 date_getseconds.coffee 的檔案中。

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

開啟 命令提示符,並按照下面顯示的方式編譯 .coffee 檔案。

c:\> coffee -c date_ getseconds.coffee

編譯後,會得到以下 JavaScript。

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

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

  console.log("The seconds in the specified date is : " + dt.getSeconds());

}).call(this);

現在,再次開啟 命令提示符,並按照下面顯示的方式執行 CoffeeScript 檔案。

c:\> coffee date_ getseconds.coffee

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

The seconds in the specified date is : 25
coffeescript_date.htm
廣告