Format Date/Time in XAML in Silverlight

user687554 picture user687554 · Apr 7, 2011 · Viewed 101.9k times · Source

I have a Silverlight 4 application. I have a C# DateTime object that I'm binding to my UI. I want this DateTime to be in the format of dd/mm/yyyy time (TimeZone). For instance, today would be displayed as

04/07/2011 at 01:13 p.m. (EST)

Is there a way to do this XAML? Or do I need to build a converter?

Answer

Vlad Bezden picture Vlad Bezden · Apr 7, 2011
<TextBlock Text="{Binding Date, StringFormat='{}{0:MM/dd/yyyy a\\t h:mm tt}'}" />

will return you

04/07/2011 at 1:28 PM (-04)