473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

.getYear function work in IE only?

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

Jul 23 '05 #1
5 1738
"What-a-Tool" <Di*************************@IHateSpam.Com> writes:
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.
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
"What-a-Tool" <Di*************************@IHateSpam.Com> wrote in message
news:VJmZd.64026$SF.11918@lakeread08...
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()
Jul 23 '05 #3

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:ll**********@hotpop.com...
"What-a-Tool" <Di*************************@IHateSpam.Com> writes:
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.
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
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

Jul 23 '05 #4
>>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.
---


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
Jul 23 '05 #5
JRS: In article <VJmZd.64026$SF.11918@lakeread08>, dated Mon, 14 Mar
2005 15:45:51, seen in news:comp.lang.javascript, What-a-Tool <Die!Frigg
in****************@IHateSpam.Com> 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 .

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
7
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj()...
2
by: Veerle | last post by:
Hello, I have made a first version of the frontpage of my new homepage. I use the small javascript <script type="text/javascript"> var modDate = new Date(document.lastModified); var day =...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
7
by: Felix Kater | last post by:
Hi, when I need to execute a general clean-up procedure (inside of a function) just before the function returns -- how do I do that when there are several returns spread over the whole function?...
2
by: Alex Nitulescu | last post by:
Hi. I have a header implemented as a user control (ascx). On start-up, I show the date/time (in a label named "lblTimer") like this: <html> ....... <span.... <%=Now.ToShortDateString() %> -...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
8
by: Paul E. Schoen | last post by:
I just noticed that my javascript app gives the wrong year in IE, but correct in Firefox, when I use: Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() + "/" +...
1
by: wangers16 | last post by:
Hi, I have the following code: date = new Date(); update = date.getYear(); document.write('<p class="copyright" align="center">© ' + update +' <a href="javascript:validate(\'' + link +...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.