The setUTCDate method sets the day of the month of the point in time stored in a Date object according to Coordinated Universal Time.
Besides, it can also be used to increase or decrease the point in time of that object in a given quantity of days.
The value returned by this method is the quantity of milliseconds passed since January 1st 1970 until the point in time stored in the Date object once it has been modified.
Syntax
myDate.setUTCDate( days )
With:
- days being an integer number that, when it is between 1 and the last day of the month in question (which can be 28, 29, 30, or 31), changes only the day of the month of the point in time stored in a Date object according to Coordinated Universal Time. Any value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining days.
- myDate being an object based on the Date object.
Instead of being instantiated from a class, in JavaScript objects are created by replicating other objects. This paradigm is called Prototype-based programming.
Example
The following code uses the setUTCDate method to change the day of the month value of a Date Object to 15 according to Coordinated Universal Time:
<script type="text/javascript">
var myDate = new Date();
var outcome = "According to Coordinated Universal Time, current date is: <br/><br/>";
outcome += myDate.toUTCString() + "<br/><br/>";
myDate.setUTCDate(15);
outcome += "After changing its day of the month to 15 according to UTC, the resulting date is: <br/><br/>";
outcome += myDate.toUTCString();
document.write(outcome);
</script>
var myDate = new Date();
var outcome = "According to Coordinated Universal Time, current date is: <br/><br/>";
outcome += myDate.toUTCString() + "<br/><br/>";
myDate.setUTCDate(15);
outcome += "After changing its day of the month to 15 according to UTC, the resulting date is: <br/><br/>";
outcome += myDate.toUTCString();
document.write(outcome);
</script>
Technical Details
The setUTCDate method belongs to the Date object, it is available since the version 1.3 of JavaScript, and it is supported in all major browsers.
JavaScript Manual >> Date Object >> setUTCDate Method