このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
Date.prototype.getSeconds()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
getSeconds() はDate インスタンスのメソッドで、地方時に基づき、指定した日時の「秒」を返します。
In this article
試してみましょう
const moonLanding = new Date("July 20, 69 00:20:18");console.log(moonLanding.getSeconds());// 予想される結果: 18構文
js
getSeconds()引数
なし。
返値
地方時に基づき、指定された日時の「秒」を表す 0 から 59 までの間の整数値です。日時が無効な場合はNaN を返します。
例
>getSeconds() の使用
変数seconds には、Date オブジェクトxmas95 に基づいて、30 という値が入ります。
js
const xmas95 = new Date("1995-12-25T23:15:30");const seconds = xmas95.getSeconds();console.log(seconds); // 30仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-date.prototype.getseconds> |