Date.prototype.getMilliseconds()

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.

getMilliseconds()Date インスタンスのメソッドで、地方時に基づき、指定された日時の「ミリ秒」を返します。

試してみましょう

const moonLanding = new Date("July 20, 69 00:20:18");
moonLanding.setMilliseconds(123);

console.log(moonLanding.getMilliseconds());
// 予想される結果: 123

構文

js
getMilliseconds()

引数

なし。

返値

地方時に基づき、指定された日時の「ミリ秒」を表す 0 から 999 までの間の数値です。日時が無効な場合は NaN を返します。

getMilliseconds() の使用

変数 milliseconds には、 Date オブジェクト xmas95 に基づいて、 0 という値が入ります。ここにはミリ秒の成分が指定されていないので、既定で 0 になります。

js
const xmas95 = new Date("1995-12-25T23:15:30");
const milliseconds = xmas95.getMilliseconds();

console.log(milliseconds); // 0

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-date.prototype.getmilliseconds

ブラウザーの互換性

関連情報