Format Date/Time in XAML in Silverlight

前端 未结 5 629
眼角桃花
眼角桃花 2020-12-08 00:02

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 (TimeZon

相关标签:
5条回答
  • 2020-12-08 00:20
    <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)

    0 讨论(0)
  • 2020-12-08 00:21

    you can also use just

    StringFormat=d
    

    in your datagrid column for date time showing

    finally it will be

       <sdk:DataGridTextColumn  Binding="{Binding Path=DeliveryDate,StringFormat=d}" Header="Delivery date" Width="*" />
    

    the out put will look like

    enter image description here

    0 讨论(0)
  • 2020-12-08 00:24

    You can use StringFormat in Silverlight 4 to provide a custom formatting of the value you bind to.

    Dates

    The date formatting has a huge range of options.

    For the DateTime of “April 17, 2004, 1:52:45 PM”

    You can either use a set of standard formats (standard formats)…

    StringFormat=f : “Saturday, April 17, 2004 1:52 PM”
    StringFormat=g : “4/17/2004 1:52 PM”
    StringFormat=m : “April 17”
    StringFormat=y : “April, 2004”
    StringFormat=t : “1:52 PM”
    StringFormat=u : “2004-04-17 13:52:45Z”
    StringFormat=o : “2004-04-17T13:52:45.0000000”
    

    … or you can create your own date formatting using letters (custom formats)

    StringFormat=’MM/dd/yy’ : “04/17/04”
    StringFormat=’MMMM dd, yyyy g’ : “April 17, 2004 A.D.”
    StringFormat=’hh:mm:ss.fff tt’ : “01:52:45.000 PM”
    
    0 讨论(0)
  • 2020-12-08 00:35

    In SL5 I found this to work:

    <TextBlock Name="textBlock" Text="{Binding JustificationDate, StringFormat=dd-MMMM-yy hh:mm}">
    <TextBlock Name="textBlock" Text="{Binding JustificationDate, StringFormat='Justification Date: \{0:dd-MMMM-yy hh:mm\}'}">
    
    0 讨论(0)
  • 2020-12-08 00:41

    C#: try this

    • yyyy(yy/yyy) - years
    • MM - months(like '03'), MMMM - months(like 'March')
    • dd - days(like 09), ffffd/ffffdd - days(Sun/Sunday)
    • hh - hour 12(AM/PM), HH - hour 24
    • mm - minute
    • ss - second

    Use some delimeter,like this:

    1. MessageBox.Show(DateValue.ToString("yyyy-MM-dd")); example result: "2014-09-30"
    2. empty format string: MessageBox.Show(DateValue.ToString()); example result: "30.09.2014 0:00:00"
    0 讨论(0)
提交回复
热议问题