please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Date.getYear() Method

Name

Date.getYear() Method---return the year field of a Date

Availability

Navigator 2.0, Internet Explorer 3.0

Synopsis

date.getYear()

Arguments

none

Returns

The year field of the specified Date object date.

Description

getYear() returns the year field of a specified Date object. The format that this year is returned in requires additional explanation, however. In Navigator 2.0 and 3.0, the return return value of this method is the year minus 1900 for dates between the years 1900 and 1999. For example, if date represents a date in 1997, then the return value would be 97. On the other hand, for dates in years prior to 1900 or after 1999, getYear() returns the year itself in Navigator 2.0 and 3.0. For example, if date represents a date in 2000, the method returns 2000 on Navigator platforms.

Internet Explorer 3.0 always returns the year minus 1900, however, so getYear() on this platform would return 85 to represent 1985, 100 to represent the year 2000 and 110 to represent 2010. IE 3.0 cannot represent years prior to 1970, so these return values are never negative numbers.

To work around these strange and incompatible return values, you should replace getYear() with a function like the following:

function getFullYear(d) returns the correct year for any year after 1000
{
    var y =index.html d.getYear();
    if (y < 1000) y += 1900;
    return y;
}

Bugs

The disparity in return values between dates in the twentieth and twenty-first centuries in Navigator is bizarre, and, if not carefully taken into account may be the source of "millennium bugs" in your code. The incompatibility between platforms makes this method especially annoying to use.

See Also

"Date", "Date.setYear()"


Previous Home Next
Date.getTimezoneOffset() Book Index Date.parse()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/refp_57.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/12/12 06:11,
TOP NEW HELP FIND: 
3.143.214.115:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/Techref/language/java/script/definitive/refp_57.htm"> [Chapter 21] Reference: Date.getYear()</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .