How To Check If New Date("some Date") Was Able To Parse Correctly?
I have the following code, which is supposed to try to parse a given date. If it fails, it defaults to the current date: var date = new Date(textbox.value); // Try to parse if (isN
Solution 1:
What Safari? Doesn't happen for me:
> a= newDate('')
InvalidDate
> isNaN(a)
true
on Safari 4.0 (either OS).
In general though JavaScript Date
parsing is traditionally largely unspecified and totally unreliable. You don't want to rely on it for user-input values as it'll exhibit inconsistent and often inappropriate behaviour across browsers, platforms and locales. It's usually better to write your own parser (or use one of the existing date libraries, eg. fleegix's).
Post a Comment for "How To Check If New Date("some Date") Was Able To Parse Correctly?"