469,626 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

problem display date in firefox

Hy all,

I have a problem with a date in javascript on firefox Browser.
I use this javascript method:
var dataNow=new Date();
var dd=dataNow.getDate();
var mm=dataNow.getMonth()+1;
var yy=dataNow.getYear();
Firefox does not display the date correctly.
Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
fine.
How can i solve that??

Thanks in advance.

Franz.
Jul 23 '05 #1
6 9192
Franz wrote:
var yy=dataNow.getYear();
Firefox does not display the date correctly.
Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
fine.


use
getFullYear()

Daniel
Jul 23 '05 #2
On 08/06/2005 09:50, Franz wrote:

[snip]
var yy=dataNow.getYear();

Firefox does not display the date correctly.
Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
fine.


Officially, there is no Date.prototype.getYear method, so an
implementation can do what it likes. However, the recommended behaviour
is the one displayed by Firefox: return the current year minus 1900.

The Date.prototype.getFullYear method is preferred as it has consistent
behaviour.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Lee
Michael Winter said:

On 08/06/2005 09:50, Franz wrote:

[snip]
var yy=dataNow.getYear();

Firefox does not display the date correctly.
Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
fine.


Officially, there is no Date.prototype.getYear method, so an
implementation can do what it likes. However, the recommended behaviour
is the one displayed by Firefox: return the current year minus 1900.


Yesterday I saw an internal report that was timestamped "1050607".

Jul 23 '05 #4
JRS: In article <42********@x-privat.org>, dated Wed, 8 Jun 2005
10:50:57, seen in news:comp.lang.javascript, Franz
<an*******@anonymous.com> posted :
I have a problem with a date in javascript on firefox Browser.
var yy=dataNow.getYear();

Firefox does not display the date correctly.
Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
fine. How can i solve that??


By reading the newsgroup FAQ; see below.

If you should need to support very very old browsers, you can use
instead of getFullYear

function getFY(D) { var YE
YE = Math.round(D.getTime() / 31556952000) + 1970
return YE + (D.getYear()-YE)%100 }

from my page js-date0.htm. The estimate YE is adjusted so that its last
two digits agree with getYear(). Of the numbers, only 100 needs to be
exact.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
"Michael Winter" <m.******@blueyonder.co.invalid> wrote in message
news:F3******************@text.news.blueyonder.co. uk...
On 08/06/2005 09:50, Franz wrote:

[snip]
var yy=dataNow.getYear();

Firefox does not display the date correctly.
Instead of "2005" for the year, it displays "105", in IE Explorer, it
looks
fine.


Officially, there is no Date.prototype.getYear method, so an
implementation can do what it likes. However, the recommended
behaviour is the one displayed by Firefox: return the current year
minus 1900.

The Date.prototype.getFullYear method is preferred as it has
consistent behaviour.


If your script might run in an environment where
Date.prototype.getFullYear is not available (since it was not introduced
until JavaScript 1.3 and JScript 3), you might be better off making sure
you a Date.prototype.getFullYear available:

if ('function' != typeof Date.prototype.getFullYear)
{
Date.prototype.getFullYear = function()
{
return (this.getYear() % 1900) + 1900;
}
}

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
JRS: In article <%Y*************@news2.mts.net>, dated Fri, 10 Jun 2005
17:19:55, seen in news:comp.lang.javascript, Grant Wagner
<gw*****@agricoreunited.com> posted :
If your script might run in an environment where
Date.prototype.getFullYear is not available (since it was not introduced
until JavaScript 1.3 and JScript 3), you might be better off making sure
you a Date.prototype.getFullYear available:
Agreed so far.
if ('function' != typeof Date.prototype.getFullYear)
{
Date.prototype.getFullYear = function()
{
return (this.getYear() % 1900) + 1900;
}
}


But only if the function always gives the correct result.

I have read, possibly here, that :-
"Method getYear can return any one of these three sequences for years :
97,98,99,00,01 or 97,98,99,2000,2001 or 97,98,99,100,101".

For 2001, those are not all equal modulo 1900; hence, that method cannot
always be right. I don't know which browser(s) give/gave 00,01.

That's why, after some thought, I produced function getFY() as
previously given in this thread and in my page js-date0.htm.

However, if the date is known to be current,
return 2000 + this.getYear()%100
will do for a while, and later on
return 2050 + (this.getYear()+50)%100
etc.

--
© 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 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Marauderz | last post: by
1 post views Thread by Agnes | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.