CoffeeScript 日期 - setUTCSeconds()



描述

setUTCSeconds() 方法根據世界標準時間設定指定日期的秒數。

語法

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

Date.setUTCSeconds(secondsValue[, msValue])

引數詳情

  • secondsValue − 一個介於 0 和 59 之間的整數,表示秒數。

  • msValue − 一個介於 0 和 999 之間的數字,表示毫秒數。

如果您未指定 msValue 引數,則使用 getUTCMilliseconds 方法返回的值。

如果您指定的引數超出預期範圍,則 setUTCSeconds 會嘗試相應地更新 Date 物件中的日期資訊。例如,如果您對 secondsValue 使用 100,則 Date 物件中儲存的分鐘數將增加 1,並且將對秒數使用 40。

示例

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

dt = new Date "February 19, 2016 23:15:00"
dt.setUTCSeconds 2   
console.log dt

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

c:\> coffee -c date_setutcseconds.coffee

編譯後,它會為您提供以下 JavaScript 程式碼。

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

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

  dt.setUTCSeconds(2);

  console.log(dt);

}).call(this);

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

c:\> coffee date_setutcseconds.coffee

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

Fri Feb 19 2016 23:15:02 GMT+0530 (India Standard Time)
coffeescript_date.htm
廣告