Cor Ligthert <no************@planet.nl> wrote:
I'd suggest using theDateTime.ToString("hh:mm tt"), if you want to
definitely use that format rather than the locale-specific short time
format.
In my humble opinion does that not work in cultures where AM and PM is not
in the standard culture setting.
You're right that it doesn't work in cultures where the AM designator
is not used at all. However, the designator may not be used in the
standard short time display, even if it's still present.
I tried it before I sent my sample part,
because I thought as well that it would work forever but it did not. (Your
"hh:mm tt" is by the way the direct translation from what Greg has sent in
cultures where AM/PM is used.)
Well, it may be - it may not be. For instance, some cultures may have
AM and PM *defined* (i.e. they *can* use the AM/PM designators) but
choose not to use them.
In other words, there are cultures where using ToShortTimeString
returns "20:05" where my code would return "8:05 PM". In fact, not only
are some cultures like that, but I happen to live in one :)
I've just run the following program:
using System;
class Test
{
static void Main()
{
DateTime dt = DateTime.Now;
Console.WriteLine (dt.ToString("hh:mm tt"));
Console.WriteLine (dt.ToShortTimeString());
}
}
and the results are:
10:19 PM
22:19
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too