JavaScript setUTCDate function is a Date Function, which is used to set Day of a Month in a given date as per the universal time.
In this article, we will show you, How to use Set UTC Date in JavaScript Programming with an example.
JavaScript setUTCDate Syntax
The basic syntax for this setUTCDate function is:
Date.setUTCDate(Day_Number)
JavaScript setUTCDate Function Example
The following example helps you understand the JavaScript set UTC Date Function. Here, we are using setUTCDate 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>
OUTPUT
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>
OUTPUT
JavaScript set UTC Date Function Example 3
If we set the Month number more than 31 then it 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>
OUTPUT