JavaScript setUTCDate

JavaScript setUTCDate function is used to set Day of a Month in a given date as per the universal time. The syntax of the JavaScript setUTCDate Date function is:

 Date.setUTCDate(Day_Number)

JavaScript setUTCDate Function Example

We are using this setUTCDate function to set the current day to 30th as per the universal time.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Set UTC Date Functions </title>
</head>
<body>
    <h1> JavaScript setUTCDate Function Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCDate (30);
  document.write("After setUTCDate () : " + dt);
</script>
</body>
</html>
JavaScript setUTCDate Example

Date and Time: Thu Nov 08 2018 12:40:51 GMT+0530 (Indian Standard Time)
After setUTCDate() : Fri Nov 30 2018 12:40:51 GMT+0530 (Indian Standard Time)

JavaScript set UTC Date Function Example 2

In this JavaScript setUTCDate example, we set the day of a custom date to 31 according to universal time.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Set UTC Date Functions </title>
</head>
<body>
    <h1> JavaScript setUTCDate Function Example </h1>
<script>
  var dt = Date("January 1, 2017 10:11:19");
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCDate (31);
  document.write("After setUTCDate () : " + dt);
</script>
</body>
</html>
JavaScript SetUTCDate Function 2

If we set the Month number more than 31, then setUTCDate will go to the next month

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Set UTC Date Functions </title>
</head>
<body>
    <h1> JavaScript setUTCDate Function Example </h1>
<script>
  var dt = Date("January 1, 2017 10:11:19");
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCDate (35);
  document.write("After setUTCDate () : " + dt);
</script>
</body>
</html>
JavaScript setUTCDate Example

Date and Time: Sun Jan 01 2017 10:11:19 GMT+0530 (Indian Standard Time)
After setUTCDate() : Sat feb 04 2017 10:11:19 GMT+0530 (Indian Standard Time)