CoffeeScript 日期 - setUTCMilliseconds()



描述

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

語法

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

Date.setUTCMilliseconds(millisecondsValue)

引數詳情

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

如果指定的引數超出預期範圍,setUTCMilliseconds 會嘗試相應地更新 Date 物件中的日期資訊。例如,如果將 1100 用於 millisecondsValue,則 Date 物件中儲存的秒數將增加 1,而毫秒數將使用 100。

示例

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

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

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

c:\> coffee -c date_setutcmilliseconds.coffee

編譯後,它會生成以下 JavaScript 程式碼。

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

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

  dt.setUTCMilliseconds(1100);

  console.log(dt);

}).call(this);

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

c:\> coffee date_setutcmilliseconds.coffee

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

Fri Feb 19 2016 23:15:01 GMT+0530 (India Standard Time)
coffeescript_date.htm
廣告
© . All rights reserved.