A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime below:

Date.prototype.setTime() - JavaScript | MDN

Date.prototype.setTime()

Baseline Widely available

setTime() は Date インスタンスのメソッドで、この日付のタイムスタンプを変更します。これは、 UTC の 1970 年 1 月 1 日午前 0 時を元期として定義される、元期からのミリ秒数です。

試してみましょう
const launchDate = new Date("July 1, 1999, 12:00:00");
const futureDate = new Date();
futureDate.setTime(launchDate.getTime());

console.log(futureDate);
// 予想される結果: "Thu Jul 01 1999 12:00:00 GMT+0200 (CEST)"

const fiveMinutesInMs = 5 * 60 * 1000;
futureDate.setTime(futureDate.getTime() + fiveMinutesInMs);

console.log(futureDate);
// 予想される結果: "Thu Jul 01 1999 12:05:00 GMT+0200 (CEST)"
// メモ: 時間帯は変更されることがあります。
構文 引数
timeValue

新しいタイムスタンプを表す整数で、協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 からのミリ秒数です。

返値

その場で Date オブジェクトを変更し、新しいタイムスタンプを返します。 timeValue が NaN (または undefined など、 NaN に変換されるその他の値)の場合、日付は無効な日時に設定され、 NaN が返されます。

例 setTime() の使用
const theBigDay = new Date("1999-07-01");
const sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4