473,398 Members | 2,404 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,398 software developers and data experts.

Who's fault: different displays of date

The following code produces different dates on different browers on my
computer.

For today on the IE it is: 2005.9.27 which is correct, but on FF is:
105.9.27 which in incorrect.

I copied the code free from somewhere. Are the different displays the
fault of browser, computer or code? Thanks.

<script type="text/javascript" language="javascript">
var today_date= new Date()
var myyear=today_date.getYear()
var mymonth=today_date.getMonth()+1
var mytoday=today_date.getDate()

document.write("Today is: ")
document.write(myyear+"."+mymonth+"."+mytoday)
</script>

Sep 27 '05 #1
5 1489
By the way, the page containing the code is in:

www.pinyinology.com

The date in discussion is at the right lower corner of the page, with
black background and white writing. I changed the Chinese language to
'Today is: ' in English wben posting it to this forum. But the results
are same.

Dung Ping wrote:
The following code produces different dates on different browers on my
computer.

For today on the IE it is: 2005.9.27 which is correct, but on FF is:
105.9.27 which in incorrect.

I copied the code free from somewhere. Are the different displays the
fault of browser, computer or code? Thanks.

<script type="text/javascript" language="javascript">
var today_date= new Date()
var myyear=today_date.getYear()
var mymonth=today_date.getMonth()+1
var mytoday=today_date.getDate()

document.write("Today is: ")
document.write(myyear+"."+mymonth+"."+mytoday)
</script>


Sep 27 '05 #2
Dung Ping wrote:
The following code produces different dates on different browers on my
computer.

For today on the IE it is: 2005.9.27 which is correct, but on FF is:
105.9.27 which in incorrect.
It is correct, it's just not what you expect. Read the ECMA spec
section 15.9 Date Objects.

I copied the code free from somewhere. Are the different displays the
fault of browser, computer or code? Thanks.

<script type="text/javascript" language="javascript">
The language attribute is depreciated, type is required.

<script type="text/javascript">
var today_date= new Date()
var myyear=today_date.getYear()
It is also a good idea to always use semi-colons to end statements, even
though they aren't always required in the source code.

getYear() returns the current year - 1900, so the result you get is
exactly what the spec says you should get. If you want 2005 rather than
105 (and who wouldn't), use getFullYear():

var myyear=today_date.getFullYear();

getFullYear is not supported by very old browsers, so if you want to
accommodate them, use one of the routines suggested here:

<URL:http://www.merlyn.demon.co.uk/js-date0.htm#gY>

var mymonth=today_date.getMonth()+1
var mytoday=today_date.getDate()

document.write("Today is: ")
document.write(myyear+"."+mymonth+"."+mytoday)
This is more efficient (though undetectably so) if written using a
single call to document.write:

document.write(
"Today is:" + myyear + "." + mymonth + "." + mytoday);

</script>

--
Rob
Sep 27 '05 #3
Lee
Dung Ping said:

The following code produces different dates on different browers on my
computer.

For today on the IE it is: 2005.9.27 which is correct, but on FF is:
105.9.27 which in incorrect.

I copied the code free from somewhere. Are the different displays the
fault of browser, computer or code? Thanks.

<script type="text/javascript" language="javascript">
var today_date= new Date()
var myyear=today_date.getYear()


It's the fault of the code.
Replace "getYear()" with "getFullYear()".

The getYear() method was originally specified to return the current
year with 1900 subtracted from it (just like the corresponding
function in the standard C library, among others).

As the year 2000 approached, some browser developers, knowing that
few Javascript coders read the documentation, began making ill-
conceived changes to the method in order to try to make it do what
most people expected.

As a result, getYear() does different things in different browsers,
and even in different versions of the same browser.

Sep 28 '05 #4
Thank all for help.

Dung Ping

Sep 28 '05 #5
JRS: In article <UL*****************@news.optus.net.au>, dated Tue, 27
Sep 2005 23:40:36, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.au> posted :
Dung Ping wrote:
To answer his Subject line - the fault lies with the stupidity of
primeval programmers, probably in California.

The value of Full Year will have been available from operating systems,
so getYear should have been coded as getFullYear in the first place, in
order not to lose information which some will need; then to get a two-
digit year is trivial for the script coder, using %100.

getFullYear is not supported by very old browsers, so if you want to
accommodate them, use one of the routines suggested here:
<URL:http://www.merlyn.demon.co.uk/js-date0.htm#gY>


That may be the right place to start, but the routines are in #gFY.

That does not include, though it does link to, Year = 2000 + Year%100
which should do for our lifetimes.

--
© 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.
Sep 28 '05 #6

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

Similar topics

59
by: Mason A. Clark | last post by:
Is there information content in this observation? use html tables for layout: http://www.microsoft.com and http://www.netscape.com uses styles: http://www.opera.com
142
by: Herr Lucifer | last post by:
As the founder of .NET framework, Microsoft claims that it invention will be the next best platform for programming in a near future. Now it is 2005, ..NET is 5 years old, and can talk and walk for...
9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
4
by: brfin999 | last post by:
Server time zone 1 hour different from Client time zone. .Net 1.1 c# Win Forms app: actual date 9/25/04 displays 9/24/04 11:00 PM. When I change client time zone to equal server time zone, date...
5
by: jeff | last post by:
i have written a program with date format as m/d/yyyy when i deploy it to client's machine, due to the client use d/m/yyyy format the Select SQL statement return some record wrongly. how can i...
10
by: Rav | last post by:
I have recently started working on GCC on red Hat 9. I have encountered with some problems that i think should not occur (at least on Turbo C), here they r: Why does the following piece of code...
6
by: elvira_wang | last post by:
Hi, i was studying the virtual memory and the page fault concept in particularly http://www.cs.man.ac.uk/~rizos/CS2051/2001-02/lect11.pdf ] Considering this concept and the two versions code...
0
by: Equinex | last post by:
Hi, I am trying to call a Web Service using Php and Soap. Why does the following Php 5 code return? try { //$ExchangeLoginResult = $ExchangeClient->Login(array("request" =>
4
by: sharsy | last post by:
Hello, I have setup an Access Database which about 7 people can enter data into. We have had a few problems where a 'fairy' has mysteriously been changing data in the table that they're not...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.