我該如何添加一個子串到lbl_diasemana標籤?如何將子句綁定到DayOfWeek var?
var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);
lbl_diasemana.Text = diasemana;
我該如何添加一個子串到lbl_diasemana標籤?如何將子句綁定到DayOfWeek var?
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);
可以在兩行代碼來完成
如果你願意,你可以做一行:lbl_diasemana.Text = new System.Globalization.CultureInfo (「pt-BR」)。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
你是什麼意思添加子..?你的意思是你如何使用子字符串函數..? – MethodMan
接收前3個字符,而不是完整的日期 –
culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(1,3) –