JavaScript 1.3 Overview, Part I: UTC-Base Set Methods - Doc JavaScript | WebReference

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:

MethodsetUTCFullYear()
Parameters<year>(mandatory)
<month>(optional)
<day of the month>(optional)
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthDate.setUTCFullYear(1998);
JavaScript 1.2setYear()

MethodsetUTCMonth()
Parameters<month>(mandatory)
<day of the month>(optional)
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthMonth.setUTCMonth(2);
JavaScript 1.2setMonth()

MethodsetUTCDate()
Parameters<day of the month>
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthDayM.setUTCDate(27);
JavaScript 1.2setDate()

MethodsetUTCHours()
Parameters<hours>(mandatory)
<minutes>(optional)
<seconds>(optional)
<milliseconds>(optional)
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthDate.setUTCHours(3, 32, 30, 509);
JavaScript 1.2setHours()

MethodsetUTCMinutes()
Parameters<minutes>(mandatory)
<seconds>(optional)
<milliseconds>(optional)
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthDate.setUTCMinutes(35, 18, 850);
JavaScript 1.2setMinutes()

MethodsetUTCSeconds()
Parameters<seconds>(mandatory)
<milliseconds>(optional)
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthDate.setUTCSeconds(43, 756);
JavaScript 1.2setSeconds()

MethodsetUTCMilliseconds()
Parameters<milliseconds>
DescriptionSets 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.
ExamplemyBirthDate = new Date();
myBirthDate.setUTCMilliseconds(103);
JavaScript 1.2None

https://www.internet.com


Created: September 14, 1998
Revised: September 14, 1998

URL: https://www.webreference.com/js/column25/dateset.html