views:

62

answers:

2

The page works fine in Chrome, but I have this one minor error in FF and a different problem in IE. Assistance with either of these issues is greatly appreciated. Since ive been stumped in the FF error the longest, I'll start with that one:

Here's the code: http://truxmapper.appspot.com/sched.html

The date picker selects a date using the format "07-08-2010 23:28". Now, I need to pass this time as a parameter to my servlet, which is expecting the time represented as a long. This is not a problem in chrome. The Date object accepts a string in the format given above, but when I try to use getTime() on a date instantiated with a string in FF, it returns NaN. So what I've done in the on the page I linked to is a little handling asking the user to re-enter the dates if its read as NaN. This obviously isnt even a bandaid solution since even if you re-enter the date its still going to read NaN. I need to know why the Date function wont instantiate using the string you see in the input text field in FF.

In IE, for some reason its telling me that sTime is undefined.

Thanks!

+5  A: 

That date format is ambiguous. Try it as yyyy-mm-dd instead of mm-dd-yyyy or dd-mm-yyyy.

no
+1  A: 
KennyTM
Wow that worked really well, thank you! I dont understand the reasoning behind your suggestion to do it that way, though. As far as the standard, i want to interface to display the date as it you see it right now. Do you recommend that I format the string so that it adheres to the standard? Also, do you understand what may be happening in IE?
culov
What's the purpose of that workaround? `new Date(dateString).getTime()` should be fine, although `new Date(Date.parse(dateString)).getTime()` could make sense also if you don't trust the Date ctor to take a string (I seem to remember that some old implementations won't). Also chrome will parse `2010-07-08 23:28:00` but not `2010-07-08T23:28:00`; I'm not sure the `T` is a good idea...
no
@Kenny: Note that the ISO8601 format was introduced by the ECMAScript 5 Standard, which is not yet widely supported, also in the previous version, ES3, there is no *standard format* described, the only requirement of the specification is that the `Date.parse` method should be able to parse a string as the `toString` or `toUTCString` methods of `Date` objects produce, and those methods are completely implementation dependent. The safest way would be to parse it manually...
CMS
@culov: I don't know what's happening in IE, as I can't test on it right now. I suggest you rearrange the date components into the form `YYYY-mm-dd HH:mm` instead of using this workaround.
KennyTM
@CMS: OK. (*checks*) Yes I've got the ES5 standard.
KennyTM
@Kenny, I didn't look carefully your first approach, note that when the `Date` constructor is called as a function (like `Date(dateString)`), it *always* returns a string representing the **current time**, regardless the arguments passed to it. The third approach should be the preferred, BTW you don't need to use the unary `+` operator, the `Date` constructor will take care to convert the args `ToNumber`.
CMS
This answer was working fine until I tested it in IE. IE doesnt like the regex and returns NaN from date.getTime()
culov
@culov: What does the IE return in `dateString.match`?
KennyTM
@Kenny It returns null
culov
@culov: Is `dateString == '07-08-2010 23:28'` or something else?
KennyTM