Temporal.PlainTime.prototype.second

Khả dụng hạn chế

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 second của các thực thể Temporal.PlainTime trả về một số nguyên từ 0 đến 59 đại diện cho thành phần giây của thời gian này.

Accessor setter của secondundefined. 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 second

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

Thay đổi second

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

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

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

Đặc tả

Thông số kỹ thuật
Temporal
# sec-get-temporal.plaintime.prototype.second

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

Xem thêm