Imagine there are two labels on a webpage both displaying a date. How would you find out which is the greater date taking into account what the users locale is.

Say Label 1 : 04/11/2009 Label 2: 09/10/2009

If it were in the US Label 2 > Label 1

If it were the UK Label 1 > Label 2

The date constructor ignores locale information so var d = new Date('04/11/2009') will always be the 11th April 2009 rather than the 4th November 2009 no matter the locale. Does anyone know any tricks to get around this? Any libraries worth checking out?

(the only wayout i can see at the moment is get the locale info using js and then parse the label so i can create a date object with another constructor but this seems to much for a supposedly simple problem?Furthermore this is not going to work well with lots of locales)

This question should be generalized to "How can I parse a Date string taking into account current locale?" Comparing the resulting dates is trivially done with less than < and greater than > operators. It's the parsing that you're really after (I think).
–
Crescent FreshNov 3 '09 at 16:02

Fair enough but its only until you try to compare (or do something) with the dates you may realise the nature of the problem
–
user48408Nov 3 '09 at 16:14

The nature of the problem becomes apparent when inspecting the result of the parse in any fashion (e.g. getDate, getMonth, Firebug, toString). Comparison is just one of many cases that will make the failure apparent.
–
Crescent FreshNov 3 '09 at 16:42

look of course you are right and thanks to some extent but sometimes and example works well to demonstrate a problem ..so take your pick people. compare, getDate, getMonth, any help appreciated
–
user48408Nov 3 '09 at 16:59