views:

66

answers:

3

I know this sucks. Date stuff sucks hard. But: Imagine a date format like "dd-MM-yyyy h:mm" how would you tell for sure what time mode that is? AM / PM or 24 hour? I'd say: If there is no "a" in the date format, then that's no AM / PM stuff and therefore it's nice 24h stuff. What do you think?

+1  A: 

You should rather check for a M or m and not an a.

Alan Haggai Alavi
+1  A: 

But "dd-MM-yyyy hh:mm" is surely an ambiguous format.

That is, parsing a date that just looks like dd-MM-yyyy hh:mm can't tell you about the 12/24 format.

You could assume it's 24h format, otherwise something is missing or it would look like "dd-MM-yyyy hh:mm X", where X is 'AM' or 'PM'.

The only truly unambiguous format is ISO 8601 'yyyy-MM-dd hh:mm' with 24h times.

pavium
kk is used instead of dd to designate 24 hour format. See the answer to his previous question. http://stackoverflow.com/questions/1378534
mahboudz
Yes, I just realised this question follows on from a previous question about a specific implementation I've never heard of before. Please ignore my answer. (I still like ISO8601, though ;-D)
pavium
+3  A: 

If you are given a date, such as 11:15, you can't know whether it is AM or PM. Just as you don't know whether when I say Deer, I mean one or more than one. As a program designer, you have to remove ambiguities or make assumptions. You could either force the data to have AM/PM, or tell the provider of the time to give it to you in 24 hour format, or you can assume that they are smart enough to realize that without AM/PM you have no way of knowing. Not knowing your situation, I can't tell you how to proceed, but there are issues that transcend plain old programming. Like whether 1,000,000,000 is a billion or a milliard or a trillion or whether a ton is 1000 kilograms or ....

mahboudz