Time Formats...

  • Thread starter Thread starter Brian H
  • Start date Start date
B

Brian H

Sanity check needed:

I have a listbox that holds a bunch of dates. I'm looking to format these
based on user settings; either a 12 or 24 hour format. I stumbled on:

http://msdn.microsoft.com/library/d...globalizationdatetimeformatinfoclasstopic.asp

Fantastic reference. It seems the "g" format pattern is ideal for my 12
hour format, producing (only minute accuracy needed):
1/3/2002 12:00 AM

But I don't see anything handy for a 24 hour format, such as:
1/3/2002 00:00

The key to this is that I want the date to support month/day/year, as well
as day/month/year. The simple format pattern ("g") will do this fine, but
I'm not sure how to do this easily for a 24 hour format. Do I need to
concatenate a ShortDateString with an HH:mm string?

Thanks for the help,
Brian
 
Hi Brian,

Is it possible to use custom date/time formatting? For example:

M/d/yyyy HH:mm -> 1/3/2002 00:00
M/d/yyyy hh:mm tt -> 1/3/2002 12:00 AM

Ryan Chapman
Software Design Engineer
.NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Ryan,

Yep -- actually as I re-read my post I realized I didn't explain the
situation very well :) -- and in thinking about it I realized doing it is
really just a few lines of code. Basically, I wanted to get away from
specifying the format too strictly because of international date formats
(M/d vs d/M); Yeah, I didn't really explain that! In the end I just
concatenated a format string based on local settings/preferences, so the
date/time will always be displayed correctly.

Thanks for the help,
Brian
 
Back
Top