JavaScript 1.3 Overview, Part I: New Date Methods - Doc JavaScript | WebReference

JavaScript 1.3 Overview, Part I: New Date Methods - Doc JavaScript


New Date Methods

JavaScript 1.3 introduces new and modified Date methods to support a full-year notation, milliseconds, and Universal Coordinate Time. The following table summarizes the new methods:

MethodgetFullYear()
ParametersNone
DescriptionReturns the year of the specified date according to local time.
Examplevar myBirthYear;
myBirthDate = new Date();
myBirthYear = myBirthDate.getFullYear();
JavaScript 1.2getYear()

MethodsetFullYear()
Parameters<year>(mandatory)
<month>(optional)
<day of the month>(optional)
DescriptionSets the year of the specified date according to local time. If you don't specify the <month> and <day of the month>, the values returned from getMonth() and getDate() 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.
Examplevar myBirthYear;
myBirthDate = new Date();
myBirthDate.setFullYear(1998);
JavaScript 1.2setYear()

MethodgetMilliseconds()
ParametersNone
DescriptionReturns the milliseconds in the specified date according to local time. The return value is between 0 and 999.
Examplevar myBirthDayMS;
myBirthDate = new Date();
myBirthDayMS = myBirthDate.getMilliseconds();
JavaScript 1.2None

MethodsetMilliseconds()
Parameters<milliseconds>
DescriptionSets the milliseconds in the specified date according to local 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.setMilliseconds(103);
JavaScript 1.2None

MethodtoUTCString()
ParametersNone
DescriptionConverts a date to a string, using UTC convention. This method behaves the same as toGMTString(), but you should use the toUTCString() instead. The latter is kept for backward compatibility purposes only.
Examplevar myBirthMonth;
myBirthDate = new Date();
myBirthMonth = myBirthDate.getUTCMonth();
JavaScript 1.2getMonth()

https://www.internet.com


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

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