Temporal.PlainTime.prototype.hour

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Thuộc tính truy cập hour của các thực thể Temporal.PlainTime trả về một số nguyên từ 0 đến 23 đại diện cho thành phần giờ của thời gian này.

Accessor setter của hourundefined. Bạn không thể thay đổi thuộc tính này trực tiếp. Sử dụng phương thức with() để tạo một đối tượng Temporal.PlainTime mới với giá trị mong muốn.

Ví dụ

Sử dụng hour

js
const time = Temporal.PlainTime.from("12:34:56");
console.log(time.hour); // 12

Thay đổi hour

js
const time = Temporal.PlainTime.from("12:34:56");
const newTime = time.with({ hour: 15 });
console.log(newTime.toString()); // 15:34:56

Bạn cũng có thể sử dụng add() hoặc subtract() để di chuyển một số giờ nhất định từ thời gian hiện tại.

js
const time = Temporal.PlainTime.from("12:34:56");
const newTime = time.add({ hours: 3 });
console.log(newTime.toString()); // 15:34:56

Đặc tả

Specification
Temporal
# sec-get-temporal.plaintime.prototype.hour

Tương thích trình duyệt

Xem thêm