spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column25


New Date Methods

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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()

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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