是否有一個簡單的內置函數,可以用來從日曆/年度組合中獲取日期實例?將日曆轉換爲日期
應該可以在文本框中輸入10w2005
,我將從中創建日期07 March 2005
。
星期一應該是第一天,CalendarWeekRule應該是FirstFullWeek。
我的第一種方法是:
Dim w As Int32 = 10
Dim y As Int32 = 2005
Dim d As New Date(y, 1, 1)
d = d.AddDays(7 * w)
但由於沒有應用FirstDay- CalendarWeekRule這不起作用。
在此先感謝
編輯:
這是我和(感謝fjdumont的鏈接)結束:
Public Shared Function FirstDateOfWeek(ByVal year As Integer, ByVal weekOfYear As Integer) As DateTime
Dim jan1 As New DateTime(year, 1, 1)
Dim daysOffset As Integer = CInt(Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek) - CInt(jan1.DayOfWeek)
Dim firstWeekDay As DateTime = jan1.AddDays(daysOffset)
Dim curCulture As System.Globalization.CultureInfo = System.Globalization.CultureInfo.CurrentCulture
Dim firstWeek As Integer = curCulture.Calendar.GetWeekOfYear(jan1, curCulture.DateTimeFormat.CalendarWeekRule, curCulture.DateTimeFormat.FirstDayOfWeek)
If firstWeek <= 1 Then
weekOfYear -= 1
End If
Return firstWeekDay.AddDays(weekOfYear * 7)
End Function
所以答案是:有沒有簡單的內置函數。謝謝。 – 2011-01-20 13:01:16