Closed
Bug 625447
Opened 14 years ago
Closed 14 years ago
Javascript date's toString() produces different output on different platforms.
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
INVALID
People
(Reporter: mark2, Unassigned)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Use firefox 3.6.13 on windows and on linux and visit a page that has:
<script language="Javascript">
Xmas95 = new Date("2009 06 12,12:52:39");
alert(Xmas95.toString());
</script>
On Windows the timezone will be represented as full English words: "Eastern Daylight Time". On Linux, the timezone will be represented as just the 3 letter code "EDT".
Reproducible: Always
Steps to Reproduce:
1. visit any page that calls a date object's toString() method on two different OS platforms.
Expected Results:
The exact same date format should be produced by the same browser version.
The date format should not vary depending on the underlying OS as this makes it more difficult for web servers to accommodate different formats and test for different operating systems for a single browser.
Updated•14 years ago
|
Assignee: nobody → general
Component: General → JavaScript Engine
OS: Linux → All
Product: Firefox → Core
QA Contact: general → general
Hardware: x86 → All
Version: unspecified → Trunk
Comment 1•14 years ago
|
||
I am sure Javascript gets the TZ info from the OS. For JS to store and handle TZ codes it seems a bit much. You can avoid these problems by using a little bit more of the Date API: https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date
![]() |
||
Comment 2•14 years ago
|
||
The spec says:
15.9.5.2 Date.prototype.toString ( )
This function returns a String value. The contents of the String are
implementation-dependent, but are intended to represent the Date in the
current time zone in a convenient, human-readable form.
Note the last bit. If you're examining the results of toString() in code, you're probably not doing what you want to do.
In our case, we just call the C library function strftime with the %Z format for the timezone part of toString on dates. What that does will depend on your C library implementation, and probably on your locale too. Again, the idea is to be human-readable.
So this looks invalid to me.
Comment 3•14 years ago
|
||
Use toISOString (new in ES5) or else crack the date apart however you like with getFullYear(), getMonth() (note that it is 0-based), etc.
js> Xmas95 = new Date("2009 06 12,12:52:39");
(new Date(1244836359000))
js> print(Xmas95.toISOString());
2009-06-12T19:52:39.000Z
/be
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•