- CoffeeScript 教程
- CoffeeScript - 首頁
- CoffeeScript - 概述
- CoffeeScript - 環境
- CoffeeScript - 命令列實用工具
- CoffeeScript - 語法
- CoffeeScript - 資料型別
- CoffeeScript - 變數
- CoffeeScript - 運算子和別名
- CoffeeScript - 條件語句
- CoffeeScript - 迴圈
- CoffeeScript - 解析
- CoffeeScript - 函式
- 面向物件的 CoffeeScript
- CoffeeScript - 字串
- CoffeeScript - 陣列
- CoffeeScript - 物件
- CoffeeScript - 範圍
- CoffeeScript - 展開
- CoffeeScript - 日期
- CoffeeScript - 數學
- CoffeeScript - 異常處理
- CoffeeScript - 正則表示式
- CoffeeScript - 類和繼承
- 高階 CoffeeScript
- CoffeeScript - Ajax
- CoffeeScript - jQuery
- CoffeeScript - MongoDB
- CoffeeScript - SQLite
- CoffeeScript 有用資源
- CoffeeScript - 快速指南
- CoffeeScript - 有用資源
- CoffeeScript - 討論
CoffeeScript 日期 - setSeconds()
說明
setSeconds() 方法根據本地時間設定指定日期的秒數
語法
下面是 setSeconds() 方法的語法。
Date.setSeconds(secondsValue[, msValue])
引數詳情
secondsValue - 0 到 59 之間的整數。
msValue - 0 到 999 之間的數字,表示毫秒。
如果未指定 msValue 引數,則使用 getMilliseconds 方法返回的值。如果指定的引數超出了預期範圍,setSeconds 會嘗試相應地更新 Date 物件中的日期資訊。例如,如果 secondsValue 使用 100,則 Date 物件中儲存的分鐘將增加 1,並將使用 40 表示秒。
示例
以下示例演示了 CoffeeScript 中 setSeconds() 方法的使用。將此程式碼儲存在名為 date_setseconds.coffee 的檔案中。
dt = new Date "February 19, 2016 23:15:00" dt.setSeconds 25 console.log dt
開啟 命令提示符,並編譯 .coffee 檔案,如下所示。
c:\> coffee -c date_setseconds.coffee
在編譯時,它會生成以下 JavaScript。
// Generated by CoffeeScript 1.10.0
(function() {
var dt;
dt = new Date("February 19, 2016 23:15:00");
dt.setSeconds(25);
console.log(dt);
}).call(this);
現在,再次開啟 命令提示符,並執行 CoffeeScript 檔案,如下所示。
c:\> coffee date_setseconds.coffee
執行後,CoffeeScript 檔案會生成以下輸出。
Fri Feb 19 2016 23:15:25 GMT+0530 (India Standard Time)
coffeescript_date.htm
廣告