.getYear function work in IE only?

W

What-a-Tool

Why is it that the following code displays "2005" in IE, but "105" in every
other browser I've tried?

var mydt = new Date();
var myyr = mydt.getYear();
document.write("<p>Year Test : "+myyr+"</p>");

Thanks in advance

--

/ Sean the Mc /

"Opinions are like flatulence - everyone loves the sound of their own, but
anyone else's usually just stinks !"
-anonymous
 
L

Lasse Reichstein Nielsen

What-a-Tool said:
Why is it that the following code displays "2005" in IE, but "105" in every
other browser I've tried?

When IE does one thing and every other browser does something else, I'd put
money on IE not following the standard.

In this case, there actually is no standard. ECMA 262 only suggests a behavior
for getYear, and Microsoft has chosen not to follow it.
---
B.2.4 Date.prototype.getYear ( )
NOTE
The getFullYear method is preferred for nearly all purposes, because it avoids the "year 2000 problem."
When the getYear method is called with no arguments the following steps are taken:
1. Let t be this time value.
2. If t is NaN, return NaN.
3. Return YearFromTime(LocalTime(t)) - 1900.
 
M

McKirahan

What-a-Tool said:
Why is it that the following code displays "2005" in IE, but "105" in every
other browser I've tried?

var mydt = new Date();
var myyr = mydt.getYear();
document.write("<p>Year Test : "+myyr+"</p>");

Thanks in advance

--

/ Sean the Mc /

"Opinions are like flatulence - everyone loves the sound of their own, but
anyone else's usually just stinks !"
-anonymous

try .getFullYear()
 
W

What-a-Tool

Lasse Reichstein Nielsen said:
When IE does one thing and every other browser does something else, I'd
put
money on IE not following the standard.

In this case, there actually is no standard. ECMA 262 only suggests a
behavior
for getYear, and Microsoft has chosen not to follow it.
---
B.2.4 Date.prototype.getYear ( )
NOTE
The getFullYear method is preferred for nearly all purposes, because it
avoids the "year 2000 problem."
When the getYear method is called with no arguments the following steps
are taken:
1. Let t be this time value.
2. If t is NaN, return NaN.
3. Return YearFromTime(LocalTime(t)) - 1900.
---

/L
--
Lasse Reichstein Nielsen - (e-mail address removed)
DHTML Death Colors:
<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


------------------------------------------------------------------

AhHah! Thanks for the help

--

/ Sean the Mc /

"Opinions are like flatulence - everyone loves the sound of their own, but
anyone else's usually just stinks !"
-anonymous
 
D

Douglas Crockford

Why is it that the following code displays "2005" in IE, but "105" in every
When IE does one thing and every other browser does something else, I'd put
money on IE not following the standard.

In this case, there actually is no standard. ECMA 262 only suggests a behavior
for getYear, and Microsoft has chosen not to follow it.
---
B.2.4 Date.prototype.getYear ( )
NOTE
The getFullYear method is preferred for nearly all purposes, because it avoids the "year 2000 problem."
When the getYear method is called with no arguments the following steps are taken:
1. Let t be this time value.
2. If t is NaN, return NaN.
3. Return YearFromTime(LocalTime(t)) - 1900.
---

JavaScript was released in 1995, and was not Y2K ready.
In Microsoft's defense, the suggested behavior is stupid.

Cosmetically, I think year % 100 would have been a better choice,
but at least Microsoft's choice is defensible.

http://www.crockford.com/javascript
 
D

Dr John Stockton

JRS: In article <VJmZd.64026$SF.11918@lakeread08>, dated Mon, 14 Mar
2005 15:45:51, seen in What-a-Tool <Die!Frigg
[email protected]> posted :
Why is it that the following code displays "2005" in IE, but "105" in every
other browser I've tried?

Because, AIUI, you have not yet tried enough browsers. I've heard that
5 can be returned by getYear().

Read the newsgroup FAQ; see below.

Use instead getFullYear, unless you need to support very old systems; in
that case, use a function getFY that calculates the proper year number
from getYear and getTime .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top