CoffeeScript 日期 - setUTCMinutes()



描述

setUTCMinutes() 方法根據世界標準時間設定指定日期的分鐘。

語法

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

Date.setUTCMinutes(minutesValue[, secondsValue[, msValue]])

引數詳情

  • minutesValue - 一個介於 0 和 59 之間的整數,表示分鐘。

  • secondsValue - 一個介於 0 和 59 之間的整數,表示秒數。如果指定了 secondsValue 引數,則也必須指定 minutesValue。

  • msValue - 一個介於 0 和 999 之間的數字,表示毫秒。如果指定了 msValue 引數,則也必須指定 minutesValue 和 secondsValue。

如果不指定 secondsValue 和 msValue 引數,則使用 getUTCSeconds 和 getUTCMilliseconds 方法返回的值。

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

示例

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

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

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

c:\> coffee -c date_setutcminutes.coffee

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

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

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

  dt.setUTCMinutes(65);

  console.log(dt);

}).call(this);

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

c:\> coffee date_setutcminutes.coffee

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

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