In this particular case, I would inform the user of the parsing error
because there is no way the system should be able to return a date/time
string in such a format. Even if the user is using 24 hour time format and
adds the am/pm, as in this case, the am/pm would return as pm for 1300.
--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
13:00am is more than 'not an acceptable time format', its simpler than
that - its not a valid time at all !
Can you just do some simple check yourself after getting the string from the
user. If the string ends in 'am' or 'pm', then the number before it can't be
higher than 1200 or 12:00. If the last digit is a number, then it needs to
be in the range 00:00 or 0000 to 23:59 or 2359.
Moreover, You could also use
try / catch( CMemoryException ) / catch( COleException )
blocks to handle all possible exceptions.
Victor
"Ronnie" <Ron...@discussions.microsoft.com> wrote in message
news:D50178EA-2A33-41A5...@microsoft.com...
But it's difficult to check am/pm symbols in 12-hour format for different
locale settings. The am/pm symbols can be "am/pm" or "上午/下午" in china, and in
other locale settings, these symbols may be different.
So, if we want to parse the string, we must known all 12-hour format
representation in different locales. It may be a little difficult.
Can't you just ignore the am/pm signals - no matter what the characters
actually are, there are only 12 hours in a morning and afternoon!. If you
start at the end of the string and work forwards, you will reach a number
which is the time. If the number is right at the end of the string, then it
is 24 hours, if the number is not the last thing in the string, then it is
12 hours and you can validate the number accordingly.