Date.prototype.setTime()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
setTime()
方法將從 1970 年 01 月 01 日 00:00:00 UTC 起所經過的毫秒數設置為 Date
物件的值。
嘗試一下
語法
js
setTime(timeValue)
參數
timeValue
-
一個整數,表示自 1970 年 01 月 01 日 00:00:00 UTC 起所經過的毫秒數。
返回值
1970 年 01 月 01 日 00:00:00 UTC 與更新日期之間的毫秒數(實際上是參數值)。
描述
以 setTime()
方法指派一日期與時間至另一 Date
物件。
範例
使用 setTime()
js
const theBigDay = new Date("July 1, 1999");
const sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
規範
Specification |
---|
ECMAScript Language Specification # sec-date.prototype.settime |
瀏覽器相容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
setTime |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.