views:

19

answers:

1

I was wondering, how do I show a 24hr clock in a WPF datagrid? At the moment, the datagrid has set itself to 12 clock, using am & pm which is just plain confusing.

In the datagrid it has a simple column binding

...and I get the following

6/29/2010 10:46:42AM 6/29/2010 11:14:10PM

alt text

+1  A: 

I'm not positive that I understand what you are asking, but I believe you just want to change the time format in your bound data?

That's fairly easy - use StringFormat. For example:

<TextBlock x:Name="txt12Hour" Text="{Binding StringFormat={}{0:hh:mm:ss tt}}" />
<TextBlock x:Name="txt24Hour" Text="{Binding StringFormat={}{0:HH:mm:ss}}" />

txt12Hour shows something like 05:17:27 PM txt24Hour shows something like 17:17:27

Use any of the same formatting rules that you'd use in a ToString() call in code. This applies not only to dates, but numbers, currencies, etc.

Wonko the Sane
Awesome, I also found this after your help. Many Thankshttp://www.csharp-examples.net/string-format-datetime/
wonea