WPF format DateTime in TextBlock

1. First add the following namespace

xmlns:sys="clr-namespace:System;assembly=mscorlib" 

2. Then add the following controls

<TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=yyyy/MM/dd HH:mm:ss}"/>

The actual effect, as shown in the figure:

Background code display time and display week, WPF

//WPF代码显示时间
Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{}&#xf017; {0:yyyy/MM/dd HH:mm:ss dddd}',ConverterCulture=zh-CN}" Style="{StaticResource FontAwesome}"


//后台代码,显示中文或英文星期和时间
txtBlockSystemTime.Text = DateTime.Now.ToString("\uf017 yyyy/MM/dd HH:mm:ss ") + DateTime.Now.ToString("dddd", LanguageResources.Current.UseEnglish ? new System.Globalization.CultureInfo("en") : new System.Globalization.CultureInfo("zh-cn"));

Guess you like

Origin blog.csdn.net/qq_36809882/article/details/122429475