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