Tutorial :Date format as 06-Apr-2009 04:25 PM



Question:

How do I format a string to display date and time such as the following?

06-Apr-2009 04:25 PM


Solution:1

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}}"/>  


Solution:2

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

theDate.ToString("dd'-'MMM'-'yyyy HH':'mm tt")  


Solution:3

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »