For passed values where the JavaScript getYear
method
returns a year less than 1000, JSV_getFullYear
returns a
four-digit number.
Use this function instead of the JavaScript getYear
method.
JSV_getFullYear(expV)
n/a
Returns a four-digit integer-valued year according to the passed variant.
The JSV_getFullYear function uses the following argument.
Argument | Description |
expV | The variant. This value can be a date object, an integer value for a year (e.g., 2000, 99 or -100), or a character string that represents a year (e.g., "2000", "99" or "-100"). |
Since we are primarily dealing with years in the 20th and 21st centuries
(i.e., years with four digits), then the JSV_getFullYear
function works
well. If the getYear
method returns anything less than a four-digit year
(i.e., a value less than 1000) we are working off a 1900-based system and
we add 1900; otherwise, the getYear
method is returning a four-digit year
(e.g., 1999 or 2000) and that is the year we want.
The JSV_getFullYear
function uses the JavaScript
getYear
method
to determine the year, and corrects to ensure the correct four-digit year is returned.
When possible, use the JavaScript getFullYear
method.
For more information on the JavaScript getYear
and
getFullYear
methods, see JavaScript Vision
Frequently Asked Questions.
n/a
The following lines of code
document.write( JSV_getFullYear(-120) );
document.write( JSV_getFullYear(0) );
document.write( JSV_getFullYear(98) );
td = new Date();
document.write( JSV_getFullYear(td) );
document.write( JSV_getFullYear(2002) );
document.write( JSV_getFullYear('102') );
produce
Copyright © 2000 Roaring Fork Software. All rights reserved.