JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Date Right Arrow setUTCDate()

setUTCDate()  Date  instance method

Description

Sets the UTC day of the month (1-31) for the specified date.

Syntax


Signature Description
aDate.setUTCDate(dayInt)Sets the UTC day of the month (1-31) for the specified date.

Parameters


Parameter Description
dayIntAn integer in the range 1-31.
  • A value of 0 will set the date to the last day of the previous month.
  • Negative values will try and set the date to the last day of the previous month and then subtract integer amount.
  • For other values the setUTCDate() method will try and set the date accordingly.

Examples

The code below shows examples of the setUTCDate() method of Date.



// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);

// Set UTC Day of the month.
todaysDate.setUTCDate(-6);
alert(todaysDate + ' - UTC Day set to -6');

todaysDate.setUTCDate(0);
alert(todaysDate + ' - UTC Day set to 0');

todaysDate.setUTCDate(35);
alert(todaysDate + ' - UTC Day set to 35');

Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times



  

go to home page Homepage go to top of page Top