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() メソッドは、Date オブジェクトを協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 からの経過時間をミリ秒単位で表す時刻に設定します。

試してみましょう

構文

js
setTime(timeValue)

引数

timeValue

協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 からの経過時間をミリ秒単位で表す整数値。

返値

協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 から更新された日時までの間のミリ秒単位の数値 (更新された日時は、引数の値になります)。

解説

setTime() メソッドは、日付と時刻を別の Date オブジェクトに代入するのに役立ちます。

setTime() の使用

js
const theBigDay = new Date("July 1, 1999");
const sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-date.prototype.settime

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
setTime

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報