Temporal.Instant.prototype.toZonedDateTimeISO()

Khả dụng hạn chế

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

Phương thức toZonedDateTimeISO() của các instance Temporal.Instant trả về một đối tượng Temporal.ZonedDateTime mới biểu diễn instant này trong múi giờ được chỉ định sử dụng hệ thống lịch ISO 8601.

Cú pháp

js
toZonedDateTimeISO(timeZone)

Tham số

timeZone

Một chuỗi hoặc instance Temporal.ZonedDateTime biểu diễn múi giờ cần sử dụng. Nếu là instance Temporal.ZonedDateTime, múi giờ của nó sẽ được dùng. Nếu là chuỗi, có thể là định danh múi giờ được đặt tên, định danh múi giờ theo offset, hoặc chuỗi date-time chứa định danh múi giờ hoặc offset (xem múi giờ và offset để biết thêm thông tin).

Giá trị trả về

Một đối tượng Temporal.ZonedDateTime mới biểu diễn instant này trong múi giờ được chỉ định sử dụng hệ thống lịch ISO 8601.

Ngoại lệ

RangeError

Được ném ra nếu tên múi giờ không hợp lệ.

TypeError

Được ném ra nếu timeZone không phải là chuỗi hoặc instance Temporal.ZonedDateTime.

Ví dụ

Sử dụng toZonedDateTimeISO()

js
const instant = Temporal.Instant.from("2021-08-01T12:34:56.123456789Z");
const zonedDateTime = instant.toZonedDateTimeISO("America/New_York");
console.log(zonedDateTime.toString()); // 2021-08-01T08:34:56.123456789-04:00[America/New_York]

const localDateTime = instant.toZonedDateTimeISO(Temporal.Now.timeZoneId());
console.log(localDateTime.toString()); // Instant này trong múi giờ của bạn

Đặc tả

Thông số kỹ thuật
Temporal
# sec-temporal.instant.prototype.tozoneddatetimeiso

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

Xem thêm