大网数据广告活动
Web 标准与前端开发

Temporal.ZonedDateTime.prototype.day

· 52CE 我爱测

The **`day`** accessor property of Temporal.ZonedDateTime instances returns a positive integer representing the 1-based day index in the month of this date, which is the same day number you would see on a calendar. It is calendar-dependent.

The day accessor property of Temporal.ZonedDateTime instances returns a positive integer representing the 1-based day index in the month of this date, which is the same day number you would see on a calendar. It is calendar-dependent.

The set accessor of day is undefined. You cannot change this property directly. Use the Temporal/ZonedDateTime/with method to create a new Temporal.ZonedDateTime object with the desired new value.

For general information and more examples, see Temporal/PlainDate/day.

For PlainDate, day can only be non-continuous if the calendar skips days. For ZonedDateTime, day can also be non-continuous if the time zone changes its offset by 24 hours; this actually happened. See the example below.

Examples

Using day

const dt = Temporal.ZonedDateTime.from("2021-07-01[America/New_York]"); // ISO 8601 calendar
console.log(dt.day); // 1

Non-continuous day

To better align times with its trading partners in Asia, the country of Samoa changed its time zone to the other side of the International Date Line, shifting its offset from -10:00 to +14:00 (daylight saving time). This resulted in a 24-hour abrupt change in the local time, therefore skipping the day December 30, 2011 entirely. 2011-12-29T23:59:59-10:00[Pacific/Apia] is immediately followed by 2011-12-31T00:00:00+14:00[Pacific/Apia].

const dt = Temporal.ZonedDateTime.from(
  "2011-12-29T23:59:59-10:00[Pacific/Apia]",
);
console.log(dt.day); // 29
const nextDay = dt.add({ seconds: 1 });
console.log(nextDay.day); // 31

For this reason, you should always prefer Temporal/ZonedDateTime/add and Temporal/ZonedDateTime/subtract to manipulate dates and times, rather than directly changing the day property.

Specifications

Browser compatibility

See also

  • Temporal.ZonedDateTime
  • Temporal/ZonedDateTime/with
  • Temporal/ZonedDateTime/add
  • Temporal/ZonedDateTime/subtract
  • Temporal/ZonedDateTime/year
  • Temporal/ZonedDateTime/month
  • Temporal/ZonedDateTime/daysInMonth
  • Temporal/ZonedDateTime/dayOfWeek
  • Temporal/ZonedDateTime/dayOfYear
  • Temporal/PlainDate/day

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。