w3resource

JavaScript setUTCdate() Method: Date Object

Description

The setUTCdate() method is used to set the numeric day of the month according to Coordinated Universal Time (UTC).

Version

Implemented in JavaScript 1.3

Syntax

setUTCdate(dayValue)

Parameter

dayValue: An integer from 1 to 31, representing the day of the month

If the specified parameter is outside the expected range, setUTCDate try to update the date information in the Date object accordingly. For example, if you use 37 for day value, and the month stored in the Date object is April, the day will be changed to 7 and the month will be next of April i.e. May.

javas script date object setutcdate method

Example:

In the following web document the day of the current month sets with various values with setUTCDate() method

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>JavaScript date object - setUTCDate() method example</title>
</head>
<body>
<h1 style="color: red">JavaScript date object : setUTCDate() method</h1>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
user_date = new Date()
document.write("Current Date : "+user_date+"<BR />")
user_date.setUTCDate(20)
document.write("Changing the current date to 20 : "+user_date+"<BR />")
user_date.setUTCDate(188)
document.write("Changing the current date to 188: "+user_date+"<BR />")
//]]>
</script>
</body>
</html>

View the example in the browser

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also:

JavaScript Core objects, methods, properties.

Previous: JavaScript setTime()Method: Date Object
Next: JavaScript setUTCfullyear() Method: Date Object

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.