Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Date
  6. setUTCMonth()

Date.prototype.setUTCMonth()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

ThesetUTCMonth() method ofDate instances changes the month and/or day of the month for this date according to universal time.

Try it

const event = new Date("December 31, 1975 23:15:30 GMT-3:00");console.log(event.toUTCString());// Expected output: "Thu, 01 Jan 1976 02:15:30 GMT"console.log(event.getUTCMonth());// Expected output: 0event.setUTCMonth(11);console.log(event.toUTCString());// Expected output: "Wed, 01 Dec 1976 02:15:30 GMT"

Syntax

js
setUTCMonth(monthValue)setUTCMonth(monthValue, dateValue)

Parameters

monthValue

An integer representing the month: 0 for January, 1 for February, and so on.

dateValueOptional

An integer from 1 to 31 representing the day of the month.

Return value

Changes theDate object in place, and returns its newtimestamp. If a parameter isNaN (or other values that getcoerced toNaN, such asundefined), the date is set toInvalid Date andNaN is returned.

Description

If you do not specify thedateValue parameter, the value returned from thegetUTCDate() method is used.

If a parameter you specify is outside of the expected range,setUTCMonth()attempts to update the date information in theDate object accordingly.For example, if you use 15 formonthValue, the year will be incremented by1, and 3 will be used for month.

Examples

Using setUTCMonth()

js
const theBigDay = new Date();theBigDay.setUTCMonth(11);

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-date.prototype.setutcmonth

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp