Home » JavaScript Date setUTCDate() Method

JavaScript Date setUTCDate() Method

by Online Tutorials Library

JavaScript Date setUTCDate() method

The JavaScript date setUTCDate() method is used to set the day of the Date object on the basis of universal time. If the given day value is outside the range of the month, the setUTCDate() method will adjust the Date object accordingly.

Syntax

The setUTCDate() method is represented by the following syntax:

Parameter

dayValue – It represents the day of the month.

JavaScript Date setUTCDate() method example

Here, we will understand setUTCDate() method through various examples.

Example 1

Let’s see an example to set the day on today’s date.

Test it Now

Output:

Today's day : 9  Updated day : 15   

Example 2

Let’s see an example to update the day of the given date.

Test it Now

Output:

Updated day : 20  

Example 3

In this example, we will provide the day value more than the days present in the month. In this case, the setUTCDate() will adjust the Date object to the next month.

Test it Now

Output:

Previous date : 15/8/1947  Updated date : 1/9/1947  

Example 4

In this example, we will provide the day value less than the days present in the month. In this case, the setUTCDate() will adjust the Date object to the previous month.

Test it Now

Output:

Previous date : 15/8/1947  Updated date : 31/7/1947  
Next TopicJavaScript Date

You may also like