I don't exactly understand what you're asking here Paul. It almost
sounds like a rhetorical question.
Have I thought of doing that? Not really... I mean, .NET has the
functions built into the format of the DateTime object to handle this
for you.
You can look at all the methods that the DateTime object already has:
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp
You can also use the Built In Format Strings
DateTime.ToString(string)
http://msdn.microsoft.com/library/d...e/html/cpconstandarddatetimeformatstrings.asp
Or you can even do your own custom DateTime formatting:
DateTime.ToString(formatString)
http://msdn.microsoft.com/library/d...ide/html/cpconcustomdatetimeformatstrings.asp
For example, I like to use the Custom DateTime Formatting a lot, since
what the DateTime object provides don't usually fit the format I'm
looking for.
Since you want it to show the AM or PM, you can use the following
format String.
Assumming the current time is 14:50:00 using the 24 hour clock and that
you want to display it with AM or PM and in the 12 hour clock format
like "02:50:00 PM",
You would do this...
DateTime.ToString("hh:mm:ss tt")
The "tt" portion of the string will show the AM or PM. the "hh" is for
hours 1-12 (just use one h if you don't want to display a leading
zero), mm for minutes, ss for seconds.
But if you just wanted to show the AM or PM and not the time, maybe you
just wanted to know if it was the morning or afternoon/night, then you
can do the following...
if DateTime.ToString("tt").Equals("AM") then...
Or you can just use the 24 hour clock and see if the hour is >= 12 just
like you have in your line of code above.
Take a look at the custom date formatting strings as you can really do
many things with it.
I guess it's really a matter of style, but if you're talking about
displaying the time as a string, then I really recommend using the
custom formatting strings as you can pretty much get any format you
would ever need.
Derek Woo