Documentación offline JavaScript main

Temporal.PlainDateTime.prototype.monthCode

main Documentación oficial Licencia CC-BY-SA-2.5Descargado el 2026-08-02

En esta página

The monthCode accessor property of {{jsxref("Temporal.PlainDateTime")}} instances returns a calendar-specific string representing the month of this date. It is calendar-dependent.

Usually it is M plus a two-digit month number. For leap months, it is the previous month's code followed by L (even if it's conceptually a derivative of the following month; for example, in the Hebrew calendar, Adar I has code M05L but Adar II has code M06). If the leap month is the first month of the year, the code is M00L.

The set accessor of monthCode is undefined. You cannot change this property directly. Use the {{jsxref("Temporal/PlainDateTime/with", "with()")}} method to create a new Temporal.PlainDateTime object with the desired new value.

For general information and more examples, see {{jsxref("Temporal/PlainDate/monthCode", "Temporal.PlainDate.prototype.monthCode")}}.

Examples#

Using monthCode#

const date = Temporal.PlainDateTime.from("2021-07-01"); // ISO 8601 calendar
console.log(date.monthCode); // "M07"
console.log(date.month); // 7

Specifications#

{{Specifications}}

Browser compatibility#

{{Compat}}

See also#

  • {{jsxref("Temporal.PlainDateTime")}}
  • {{jsxref("Temporal/PlainDateTime/with", "Temporal.PlainDateTime.prototype.with()")}}
  • {{jsxref("Temporal/PlainDateTime/add", "Temporal.PlainDateTime.prototype.add()")}}
  • {{jsxref("Temporal/PlainDateTime/subtract", "Temporal.PlainDateTime.prototype.subtract()")}}
  • {{jsxref("Temporal/PlainDateTime/year", "Temporal.PlainDateTime.prototype.year")}}
  • {{jsxref("Temporal/PlainDateTime/month", "Temporal.PlainDateTime.prototype.month")}}
  • {{jsxref("Temporal/PlainDateTime/daysInMonth", "Temporal.PlainDateTime.prototype.daysInMonth")}}
  • {{jsxref("Temporal/PlainDateTime/monthsInYear", "Temporal.PlainDateTime.prototype.monthsInYear")}}
  • {{jsxref("Temporal/PlainDate/monthCode", "Temporal.PlainDate.prototype.monthCode")}}