5

今天是 21.10.2012。现在是星期天。
但我的 VB.NET 认为不同:

Debug.Print("Weekday for the date '21.10.2012.'is " & WeekdayName(Weekday("21.10.2012.")))
Debug.Print("Weekday for the date '21/10/2012'is " & WeekdayName(Weekday("21/10/2012")))
Debug.Print("Weekday for the date '" & DateTime.Now.Date & "'is " & WeekdayName(Weekday(DateTime.Now.Date)))

所有这 3 次检查都给了我:工作日名称的“星期一”!
如何获得正确的工作日名称?

4

2 回答 2

10

这是获取给定日期的工作日名称的正确 .NET 方法:

Dim myCulture As System.Globalization.CultureInfo = Globalization.CultureInfo.CurrentCulture
Dim dayOfWeek As DayOfWeek = myCulture.Calendar.GetDayOfWeek(Date.Today)
' dayOfWeek.ToString() would return "Sunday" but it's an enum value,
' the correct dayname can be retrieved via DateTimeFormat.
' Following returns "Sonntag" for me since i'm in germany '
Dim dayName As String = myCulture.DateTimeFormat.GetDayName(dayOfWeek)
于 2012-10-20T23:12:49.627 回答
2
 Label1.Text = Date.Today.ToString("dddd")
于 2015-10-05T11:02:35.480 回答