Skip to content

Commit d62e09c

Browse files
committed
docs(temporal): edit text
1 parent 1d8c2af commit d62e09c

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

docs/temporal.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const currentYear = Temporal.Now.plainDateISO().withCalendar("chinese").year;
6666

6767
`Temporal.Instant`表示某个固定的时点。
6868

69+
Temporal.Instant.from() 方法用来新建时点实例。
70+
6971
```javascript
7072
const instant = Temporal.Instant.from('1969-07-20T20:17Z');
7173
instant.toString(); // => '1969-07-20T20:17:00Z'
@@ -77,6 +79,23 @@ const now = Temporal.Now.instant();
7779
const duration = now.until(launch, { smallestUnit: "hour" });
7880
```
7981

82+
时点实例有以下方法:
83+
84+
- toZonedDateTimeISO():返回指定时区的时间。
85+
86+
```javascript
87+
const instant = Temporal.Instant.from("2026-02-25T15:15:00Z");
88+
89+
instant.toString()
90+
// "2026-02-25T15:15:00Z"
91+
92+
instant.toZonedDateTimeISO("Europe/London").toString()
93+
// "2026-02-25T15:15:00+00:00[Europe/London]"
94+
95+
instant.toZonedDateTimeISO("America/New_York").toString()
96+
// "2026-02-25T10:15:00-05:00[America/New_York]"
97+
```
98+
8099
## Temporal.ZonedDateTime
81100

82101
`Temporal.ZonedDateTime`表示某个时区的时间。它会在 ISO8601 的标准格式后面,添加时区后缀和历法后缀。
@@ -106,6 +125,17 @@ const zonedDateTime = Temporal.ZonedDateTime.from({
106125
}); // => 1995-12-07T03:24:30.0000035-08:00[America/Los_Angeles]
107126
```
108127

128+
Temporal.ZonedDateTime.from() 也可以解析时间字符串。
129+
130+
```javascript
131+
const zdt = Temporal.ZonedDateTime.from(
132+
"2026-03-29T00:30:00+00:00[Europe/London]",
133+
);
134+
135+
console.log(zdt.toString());
136+
// "2026-03-29T00:30:00+00:00[Europe/London]"
137+
```
138+
109139
下面是使用`Temporal.ZonedDateTime.compare()`比较两个 ZonedDateTime 实例对象的例子。
110140

111141
```javascript

0 commit comments

Comments
 (0)