A RetroSearch Logo

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

Search Query:

Showing content from https://developer.cdn.mozilla.net/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours below:

Date.prototype.getHours() - JavaScript | MDN

Date.prototype.getHours()

Baseline Widely available

getHours() 方法根据本地时间,返回一个指定的日期对象的小时。

尝试一下
const birthday = new Date("March 13, 08 04:20");

console.log(birthday.getHours());
// Expected output: 4
语法 参数

无

返回值

getHours 返回一个 0 到 23 之间的整数值。

示例 示例:使用getHours方法

下面第二条语句,基于日期对象 Xmas95 的值,把 23 赋值给了变量 hours。

var Xmas95 = new Date("December 25, 1995 23:15:00");
var hours = Xmas95.getHours();

alert(hours); // 23
规范 浏览器兼容性 参见

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