如何子字符串到 DayOfWeek 变量?

How to subtring to a DayOfWeek var?

如何向 lbl_diasemana 标签添加子字符串?

var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);
lbl_diasemana.Text = diasemana;
var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(0,3);
lbl_diasemana.Text = diasemana;

使用 Substring 重载,它接受起始索引和要剪切的字符数:

lbl_diasemana.Text = diasemana.Substring(0, 3);
var culture = new System.Globalization.CultureInfo("pt-BR");
lbl_diasemana.Text = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(0, 3);

两行代码即可完成

您可以将 DateTime.Today.ToString(...) 方法与适当的格式字符串和区域性一起使用,如下所示:

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("pt-BR");
lbl_diasemana.Text = DateTime.Today.ToString("ddd", culture);

https://msdn.microsoft.com/en-us/library/8tfzyc64(v=vs.110).aspx