CoffeeScript Date - setTime()



描述

setTime() 方法將 Date 物件設定為 1970 年 1 月 1 日 00:00:00 UTC 以來表示為毫秒數的時間。

語法

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

Date.setTime(timeValue)

引數詳細資訊

  • timeValue - 一個表示自 1970 年 1 月 1 日 00:00:00 UTC 以來毫秒數的整數。

示例

以下示例演示了在 CoffeeScript 中使用 setTime() 方法。將這段程式碼另存為檔案,檔名命名為 date_settime.coffee

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

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

c:\> coffee -c date_settime.coffee

編譯時,它會給你以下 JavaScript。

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

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

  dt.setTime(5000000);

  console.log(dt);

}).call(this);

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

c:\> coffee date_settime.coffee

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

Thu Jan 01 1970 06:53:20 GMT+0530 (India Standard Time)
coffeescript_date.htm
廣告