tags:

views:

145

answers:

3

How do I format a string to display date and time as

06-Apr-2009 04:25 PM

Can any One help?

Thanks

A: 

you can check out the available DateTime formats at http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx you can also provide custom formats. if you want to display it within wpf when dealing with DateTime's, you can implement a custom IValueConverter and use the Converter within your binding to display the datetime's as you want them.

Joachim Kerschbaumer
+1  A: 

You can use a custom date format string to get exactly that format:

theDate.ToString("dd'-'MMM'-'yyyy HH':'mm tt")
Guffa
+6  A: 

WPF now has the StringFormat property on the Binding class, which you can use as follows:

<TextBlock Text="{Binding StringFormat={}{0:dd-MMM-yyyy HH:mm tt}}"/>

HTH, Kent

Kent Boogaart
I think it should be <TextBlock Text="{Binding StringFormat='{}{0:dd-MMM-yyyy HH:mm tt}'}"/>
Pavel Chuchuva