Vb.net 获取工作日名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12993459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:22:21 来源:igfitidea点击:
Vb.net getting weekday name
提问by Wine Too
Today is 21.10.2012. and it is Sunday.
But my VB.NET think different:
今天是 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)))
All those 3 checks give me: 'Monday' for weekday name!
What to do to get proper weekday names?
所有这三张支票都给了我:“星期一”作为工作日名称!
如何获得正确的工作日名称?
回答by Tim Schmelter
This is the correct .NET way to get the weekday name of a given date:
这是获取给定日期的工作日名称的正确 .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)
回答by Dev_Manager
Label1.Text = Date.Today.ToString("dddd")