Temporal.Duration.prototype.days

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 accessor days của các instance Temporal.Duration trả về một số nguyên đại diện cho số ngày trong duration.

Trừ khi duration được cân bằng, bạn không thể giả định phạm vi của giá trị này, nhưng bạn có thể biết dấu của nó bằng cách kiểm tra thuộc tính sign của duration. Nếu nó được cân bằng thành đơn vị trên ngày, phạm vi giá trị tuyệt đối của days phụ thuộc vào lịch (số ngày trong một tuần hoặc tháng).

Set accessor của daysundefined. 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.Duration mới với giá trị mới mong muốn.

Ví dụ

Sử dụng days

js
const d1 = Temporal.Duration.from({ weeks: 1, days: 1 });
const d2 = Temporal.Duration.from({ weeks: -1, days: -1 });
const d3 = Temporal.Duration.from({ weeks: 1 });
const d4 = Temporal.Duration.from({ days: 7 });

console.log(d1.days); // 1
console.log(d2.days); // -1
console.log(d3.days); // 0
console.log(d4.days); // 7

// Balance d4
const d4Balanced = d4.round({
  largestUnit: "weeks",
  relativeTo: Temporal.PlainDate.from("2021-01-01"), // ISO 8601 calendar
});
console.log(d4Balanced.days); // 0
console.log(d4Balanced.weeks); // 1

Đặc tả

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

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

Xem thêm