Temporal.Instant.prototype.toZonedDateTimeISO()
toZonedDateTimeISO() 方法屬於 Temporal.Instant 例項,它會返回一個新的 Temporal.ZonedDateTime 物件,該物件使用 ISO 8601 日曆系統,在指定的時區表示此時間點。
語法
js
toZonedDateTimeISO(timeZone)
引數
timeZone-
一個字串或一個
Temporal.ZonedDateTime例項,表示要使用的時區。如果是Temporal.ZonedDateTime例項,則使用其時區。如果是一個字串,它可以是命名時區識別符號、偏移時區識別符號,或者包含時區識別符號或偏移的日期時間字串(有關更多資訊,請參閱時區和偏移)。
返回值
一個新的 Temporal.ZonedDateTime 物件,它使用 ISO 8601 日曆系統,在指定的時區表示此時間點。
異常
RangeError-
如果時區名稱無效,則會丟擲錯誤。
TypeError-
如果
timeZone不是字串或Temporal.ZonedDateTime例項,則丟擲此錯誤。
示例
使用 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()); // This instant in your timezone
規範
| 規範 |
|---|
| Temporal # sec-temporal.instant.prototype.tozoneddatetimeiso |
瀏覽器相容性
載入中…