简体   繁体   中英

Format datetime in a specific format

I am using a WPF TextBlock to Bind a Modified Datetime field and is showing the data , But i want to display it in a custom format like this "DD.MM.YY HH:MM" . I tried the below xaml but its not rendering the data in the requested format but it shows data as mm/dd/yyy hh:mm:ss long datetime string

<TextBlock  Text="{Binding Modified, StringFormat={}{0:DD.MM.YY  HH:MM}}" VerticalAlignment="Center" Style="{StaticResource ResourceKey=DateLabelStyle}" ></TextBlock>

How can i make it to show data in DD.MM.YY HH:MM format ? Do i need to write separate converters for doing this??

Try the following

<TextBlock Text="{Binding Modified, StringFormat=dd.MM.yy HH:mm}"/>

For more information about standard date and time formats see : http://msdn.microsoft.com/en-us/library/az4se3k1.aspx .

This can also be useful for custom date and time formats : http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx .

There is no DD and YY formats for a custom date and time format . And MM for months, mm for minutes.

I think you just need

<TextBlock Text = "{Binding Modified, StringFormat = dd.MM.yy HH:mm}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM