Movatterモバイル変換


[0]ホーム

URL:


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

Date.prototype.setUTCDate()

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⁩.

ThesetUTCDate() method ofDate instances changes the day of the month for this date according to universal time.

Try it

const event = new Date("August 19, 1975 23:15:30 GMT-3:00");console.log(event.getUTCDate());// Expected output: 20event.setUTCDate(19);console.log(event.getUTCDate());// Expected output: 19

Syntax

js
setUTCDate(dateValue)

Parameters

dateValue

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

Return value

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

Description

If thedateValue is outside of the range of date values for the month,setDate() will update theDate object accordingly.

For example, if 0 is provided fordateValue, the date will be set to the last day of the previous month. If you use 40 fordateValue, and the month stored in theDate object is June, the day will be changed to 10 and the month will be incremented to July.

If a negative number is provided fordateValue, the date will be set counting backwards from the last day of the previous month. -1 would result in the date being set to 1 day before the last day of the previous month.

Examples

Using setUTCDate()

js
const theBigDay = new Date();theBigDay.setUTCDate(20);

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp