views:

62

answers:

4
+1  Q: 

Date validation

Has someone validated date of this format

Feb 9, 2010 12:07 PM

in javascript previously.There is a problem with javascript Date object its accepting Feb 9,2010 00:07 PM as a valid date.

A: 

00 PM is noon. Seems fine to me. It won't accept any hours >12 when using AM/PM so it appears to be intended.

nicerobot
+1  A: 

If you fancy using a library, date.js is designed to handle this sort of situation.

Paul D. Waite
+2  A: 

Meridiem has its roots in Latin meaning noon or midday. So saying 00:07 PM, or in other words 7 minutes past noon is technically correct though not commonly used.

On the other hand, saying 12 PM is then incorrect as it means 12 hours past noon, or midnight.

So I guess it's more convention than anything, but 00:07 PM is indeed correct. Also, testing on Chrome correctly flags values over 12, such as 13:07 PM as an invalid date.

You might find this section on Confusion at noon and midnight in a 12 hour clock useful.

Anurag
A: 

The behavior of the Date constructor is unspecified, so even if you can explain this behavior, you cannot rely on it working the same way across other browsers. If you want reliable behavior, you should use a library like datejs or dojo.

peller