如何使用 vb.net/C# 获取自定义格式的星期名称
How get Week day name in custom format using vb.net/C#
使用以下代码获取计算机的当前日名称
Dim CompCurrCult = Globalization.CultureInfo.CurrentCulture
Dim dayOfWeek As DayOfWeek = CompCurrCult .Calendar.GetDayOfWeek(Date.Today)
结果:dayofWeek = Monday
所以我的问题是如何得到像 MON
这样的结果而不是 Monday
使用子串函数
Dim DayName As String = UCase(dayOfWeek.ToString.Substring(0, 3))
Calendar.GetDayOfWeek
method returns full day name of a DateTime
which provided as a parameter and it's based on DayOfWeek
枚举。
您可以使用 "ddd"
format specifier 获取当天的缩写名称。对于 C#;
DateTime.Today.ToString("ddd", CultureInfo.InvariantCulture); //Mon
如果你想得到它作为MON
,只需调用.ToUpper()
method like;
DateTime.Today.ToString("ddd", CultureInfo.InvariantCulture).ToUpper(); // MON
使用以下代码获取计算机的当前日名称
Dim CompCurrCult = Globalization.CultureInfo.CurrentCulture
Dim dayOfWeek As DayOfWeek = CompCurrCult .Calendar.GetDayOfWeek(Date.Today)
结果:dayofWeek = Monday
所以我的问题是如何得到像 MON
这样的结果而不是 Monday
使用子串函数
Dim DayName As String = UCase(dayOfWeek.ToString.Substring(0, 3))
Calendar.GetDayOfWeek
method returns full day name of a DateTime
which provided as a parameter and it's based on DayOfWeek
枚举。
您可以使用 "ddd"
format specifier 获取当天的缩写名称。对于 C#;
DateTime.Today.ToString("ddd", CultureInfo.InvariantCulture); //Mon
如果你想得到它作为MON
,只需调用.ToUpper()
method like;
DateTime.Today.ToString("ddd", CultureInfo.InvariantCulture).ToUpper(); // MON