JavaScript 1.3 Overview, Part I: UTC-Base Set Methods - Doc JavaScript
UTC-Base Set Methods
JavaScript 1.3 provides support for the following methods for setting different time components in a given Date
object:
Method | setUTCFullYear() |
Parameters | <year>(mandatory) <month>(optional) <day of the month>(optional) |
Description | Sets the year of the specified date according to Universal Coordinated Time. If you don't specify the <month> and <day of the month>, the values returned from getUTCMonth() and getUTCDate() are used. Notice you cannot specify the <day of the month> without specifying the <month>. If you specify a parameter outside its expected range, other parameters will be updated accordingly. If, for example, you specify 15 for the <month>, the <year> will be incremented by one, and the <month> will be set to 3 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | setYear()
|
Method | setUTCMonth() |
Parameters | <month>(mandatory) <day of the month>(optional) |
Description | Sets the month of the specified date according to Universal Coordinated Time. If you don't specify the <day of the month>, the value returned from getUTCDate() is used. The expected range of <month> is between 0 and 11 . If you specify a parameter outside its expected range, other parameters will be updated accordingly. If, for example, you specify 15 for the <month>, the <year> will be incremented by one, and the <month> will be set to 3 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | setMonth()
|
Method | setUTCDate() |
Parameters | <day of the month> |
Description | Sets the day of the month of the specified date according to Universal Coordinated Time. The expected range of <day of the month> is between 1 and 31 . If you specify a parameter outside its expected range, other parameters will be updated accordingly. If, for example, you specify 45 for the <day of the month> of June, the month of the Date object will be incremented by one to July, and the <day of the month> will be set to 15 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | setDate()
|
Method | setUTCHours() |
Parameters | <hours>(mandatory) <minutes>(optional) <seconds>(optional) <milliseconds>(optional) |
Description | Sets the hours of the specified date according to Universal Coordinated Time. If you don't specify the <minutes>, <seconds>, and <milliseconds>, the values returned from getUTCMinutes() , getUTCSeconds() and getUTCMilliseconds() are used. Notice you cannot specify the <milliseconds> parameter without specifying the <minutes> and <seconds> parameters. Similarly, you cannot specify the <seconds> parameter without specifying the <minutes> one. If you specify a parameter outside its expected range, other parameters will be updated accordingly. If, for example, you specify 1500 for the <milliseconds> parameter, the <seconds> will be incremented by one, and the <milliseconds> will be set to 500 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | setHours()
|
Method | setUTCMinutes() |
Parameters | <minutes>(mandatory) <seconds>(optional) <milliseconds>(optional) |
Description | Sets the minutes of the specified date according to Universal Coordinated Time. If you don't specify the <seconds> and <milliseconds>, the values returned from getUTCSeconds() and getUTCMilliseconds() are used. Notice you cannot specify the <milliseconds> without specifying the <seconds>. If you specify a parameter outside its expected range, other parameters will be updated accordingly. If, for example, you specify 150 for the <seconds>, the <minutes> will be incremented by two, and the <seconds> will be set to 30 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | setMinutes()
|
Method | setUTCSeconds() |
Parameters | <seconds>(mandatory) <milliseconds>(optional) |
Description | Sets the seconds of the specified date according to Universal Coordinated Time. If you don't specify the <milliseconds>, the value returned from getUTCMilliseconds() is used. The expected range of <seconds> is between 0 and 59 . If you specify a parameter outside its expected range, other parameters will be updated accordingly. If, for example, you specify 151 for the <seconds>, the minutes of the Date object will be incremented by two, and the <seconds> will be set to 31 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | setSeconds()
|
Method | setUTCMilliseconds() |
Parameters | <milliseconds> |
Description | Sets the milliseconds in the specified date according to Universal Coordinated Time. The parameter value should be between 0 and 999 . If you specify a number outside this range, other date variables in the Date object will be incremented to accommodate your number. If you specify 1012 , for example, the number of milliseconds in the Date object will be 12 and the number of seconds will be incremented by 1 . |
Example | myBirthDate = new Date(); |
JavaScript 1.2 | None |
Created: September 14, 1998
Revised: September 14, 1998
URL: https://www.webreference.com/js/column25/dateset.html