473,233 Members | 1,465 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,233 software developers and data experts.

Which should be the correct date format for Date.parse ?

Hy everybody.

I'm not a html writer, but a sysadmin who's trying to help a user able
to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1,
Firefox 0.8+) due to a javascript date check.

Let's go straight to the point:

<script language="JavaScript">
alert("Date: "+Date.parse("2000-01-01"))
// On IE and Mozilla: "Date: NaN"

alert("Date: "+Date.parse("01-01-2000"))
// On IE: "Date: 946681200000"
// On Mozilla: "Date: NaN"

alert("Date: "+Date.parse("01/01/2000"))
alert("Date: "+Date.parse("2000/01/01"))
// On IE and Mozilla: "Date: 946681200000"
</script>

This happens on italian win2000 and winxp, italian IE6, italian Moz1.6,
english Ns7.1, english Firefox 0.8.0+.

Obviously the solution is the third example, and I've yet mailed it to
the webmaster, who is using the second format, 01-01-2000; but is it
correct that in both Mozilla and IE Date.parse doesn't accept the
iso8601 format 2000-01-01 or maybe is something of which mozilla
developers should be aware? Or maybe the examples above are an improper
use of Date.parse?

I read the paragraph 15.9.4.2 of ecmascript 262 pdf, but it's not so
clear about possible date formats; or maybe it refers to something that
I cannot understand.
Thank you.
Matteo
Jul 23 '05 #1
4 43489
Matteo wrote on 15 jun 2004 in comp.lang.javascript:
Obviously the solution is the third example, and I've yet mailed it to
the webmaster, who is using the second format, 01-01-2000;


This format cannot be used, since it is regional settings dependent:

01-07-2004 means 1st of juli in some pc's but 7th of january in others.

Do not trust all Italian pc's to have been set "correctly".

Do not test on 01-01-2000, since that date will be "correct" in both
circumstances.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
Evertjan. ha scritto:
Matteo wrote on 15 jun 2004 in comp.lang.javascript:
Obviously the solution is the third example, and I've yet mailed it to
the webmaster, who is using the second format, 01-01-2000;

This format cannot be used, since it is regional settings dependent:

01-07-2004 means 1st of juli in some pc's but 7th of january in others.

Do not trust all Italian pc's to have been set "correctly".

Do not test on 01-01-2000, since that date will be "correct" in both
circumstances.


This is right; but I was wondering also why both IE and Mozilla accept
AAAA/MM/DD and don't accept AAAA-MM-DD format, that is an iso standard;
maybe Date.parse is intended to handle only long formats like '15 Jun
2004 07:59:19 GMT', and supports other formats only for proprietary
extension ?

Anyway, mine is just an academic discussion about which date standard
formats the browsers should and shouldn't accept for Date.parse;
certainly the 01-01-2000 format is an ambiguous format and must not be
used to calculate dates.

Bye.
Matteo
Jul 23 '05 #3
Matteo schrieb:
[...] I was wondering also why both IE and Mozilla accept AAAA/MM/DD
Downwards compatibility.
and don't accept AAAA-MM-DD format, that is an iso standard;
It is still the wrong format:

<http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/date.html#1193137>
<http://msdn.microsoft.com/library/en-us/script56/html/js56jsobjdate.asp?frame=true>
<http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthparse.asp?frame=true>
maybe Date.parse is intended to handle only long formats like '15 Jun
2004 07:59:19 GMT',
That may be the reason. AFAIS the ECMAScript 3 specification does
not specify the date format that Date.parse() should accept, only
ways how its argument can be interpreted.
and supports other formats only for proprietary extension ?
Apparently.
Anyway, mine is just an academic discussion about which date standard
formats the browsers should and shouldn't accept for Date.parse; [...]


Since date strings are always ambiguous, one should use

new Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ]
] ] ] )

as clearly specified in ECMAScript 3, section 15.9.3.1, instead.
PointedEars
Jul 23 '05 #4
JRS: In article <ca**********@balena.cs.interbusiness.it>, seen in
news:comp.lang.javascript, Matteo <ma******************@libNoeroSpam.it>
posted at Tue, 15 Jun 2004 19:01:47 :
Evertjan. ha scritto:
Matteo wrote on 15 jun 2004 in comp.lang.javascript:
Obviously the solution is the third example, and I've yet mailed it to
the webmaster, who is using the second format, 01-01-2000; This format cannot be used, since it is regional settings dependent:

01-07-2004 means 1st of juli in some pc's but 7th of january in others.

Do not trust all Italian pc's to have been set "correctly".

Do not test on 01-01-2000, since that date will be "correct" in both
circumstances.


This is right; but I was wondering also why both IE and Mozilla accept
AAAA/MM/DD and don't accept AAAA-MM-DD format, that is an iso standard;
maybe Date.parse is intended to handle only long formats like '15 Jun
2004 07:59:19 GMT', and supports other formats only for proprietary
extension ?


Only an optimist expects software written in the USA to understand
International Standards. They do not even understand the word
"International"; they generally use it as near-synonymous with
"Foreign". In truth, "International" means "the same world-wide
(including, if possible, the USA)" and "Multi-National" is better for
"customised, correctly or otherwise, for assumed location".

Anyway, mine is just an academic discussion about which date standard
formats the browsers should and shouldn't accept for Date.parse;
certainly the 01-01-2000 format is an ambiguous format and must not be
used to calculate dates.


It should indeed never be used, except for the Nth day of the Nth month.
I believe that the true ISO format, YYYY-MM-DD, should be used wherever
practical; but in javascript using - as a separator is at best unsafe.
I've "always" recommended and used YYYY/MM/DD in javascript, and have
never been told of any problem with it.

Actually, I think I never tried xx-xx-xxxx (knowing xxxx-xx-xx to fail);
my MSIE4 takes it as MM-DD-YYYY, which is unacceptable.

A parser should be liberal, but not to the point of accepting ambiguity.
Ideally, it would accept only "YYYYxMMxDDyHHzMMzSS Zone" in which x y &
z are any plausible separators; and there would be another form, or an
optional extra parameter, for specifying the date field order.

Your "946681200000" is of course when Year 2000 started in Italy.
Canadians get a larger number.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for 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

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

Similar topics

25
by: koray | last post by:
hi everyone, in my form i have to take some date information in dd-mm-yy format. but i don't want user to use tabs while typing. for example s/he should simply type 280104 but 28/01/04 must...
1
by: Nagina | last post by:
Hello How can i simply convert from date format "dd/mm/yyy" to "mm/dd/yyyy" using cSharp.
1
by: Keith Chadwick | last post by:
Been trying to use the ms:format-date() in one of my transformations. I have all of the necessary declarations in my xml as in <?xml version="1.0" ?> <data xml:space="default"...
1
by: '[] WiRaN | last post by:
one know format date in c#???? or validate?
1
by: Rich | last post by:
Hello, I have some datefields in a dataset (ds1). I bind some textbox controls on a windows form to these date fields in ds1, but I only want to see 01/01/2004 instead of 1/1/2004 8:00:00 AM. ...
2
by: Rahul | last post by:
Hey Guys I have a development environment, in which the whole SQL syntax is stored in the Database. So the syntax in the databse column could be "where BirthDate = '12/31/2005' and ID =...
9
by: insomniux | last post by:
Hi, I am having a problem with formatting the default value of a date field. It has been discussed earlier in many topics, but still I cannot solve the problem. What's happening: I have various...
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
1
by: jimmy | last post by:
I'm trying to insert a date into a MySQL date column. The string i am trying to insert takes the following format: 2007-02-23 which corresponds to the date format that MySQL uses which is...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youíll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.