Temporal.PlainTime.prototype.nanosecond
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 nanosecond của các thực thể Temporal.PlainTime trả về một số nguyên từ 0 đến 999 đại diện cho thành phần nano-giây (10-9 giây) của thời gian này.
Accessor setter của nanosecond là undefined. 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 nanosecond
js
const time = Temporal.PlainTime.from("12:34:56");
console.log(time.nanosecond); // 0
const time2 = Temporal.PlainTime.from("12:34:56.123456789");
console.log(time2.nanosecond); // 789
Thay đổi nanosecond
js
const time = Temporal.PlainTime.from("12:34:56");
const newTime = time.with({ nanosecond: 100 });
console.log(newTime.toString()); // 12:34:56.0000001
Bạn cũng có thể sử dụng add() hoặc subtract() để di chuyển một số nano-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.add({ nanoseconds: 100 });
console.log(newTime.toString()); // 12:34:56.0000001
Đặc tả
| Specification |
|---|
| Temporal> # sec-get-temporal.plaintime.prototype.nanosecond> |