我需要帮助转换年,周数和日至今。因此,如果date1为1990,wN为12,dDay为3,则结果应为3/21/1990 (mm/dd/yyyy格式)。
我在寻找这一行的正确格式时遇到了问题:Output(Date(date1, 1, 1) + ((wN - 1) * 7) - Weekday(Date(date1, 1, 1) + (wN - 1) * 7, 2) + 1 + (dDay - 1))
此代码在Excel中运行良好。我正在尝试将其转换为在vb.net中工作
Dim str1 As String = txtInput1.Text
Dim d2 As String
Dim date1 As Integer
Dim date2 As Integer
Dim wN As Integer
Dim dDay As Integer
Dim cYear As Integer = DateTime.Now.Year
txtOutput.Text = ""
d2 = Mid(str1, 2, 1)
wN = Mid(str1, 3, 2)
dDay = Mid(str1, 5, 1)
If d2 = "G" Then
date1 = 1990
date2 = 2013
If date2 <= cYear Then
'Output("Year Built " & date1 & " or " & date2 & vbCrLf & "Week " & wN & vbCrLf & "Day " & dDay)
Output(Date(date1, 1, 1) + ((wN - 1) * 7) - Weekday(Date(date1, 1, 1) + (wN - 1) * 7, 2) + 1 + (dDay - 1))
Else
Output("Year Built " & date1)
End If
发布于 2018-06-05 02:35:20
你的公式有点不对劲。从年初开始,并添加天数。
Const DAYS_IN_A_WEEK As Integer = 7
Dim year As Integer = 1990
Dim weekNumber As Integer = 12
Dim dayOfWeek As Integer = 3
Dim calculatedDate = New DateTime(year, 1, 1)
calculatedDate = calculatedDate.AddDays((weekNumber - 1) * DAYS_IN_A_WEEK + (dayOfWeek - 1) - (CInt(calculatedDate.DayOfWeek) - 1))
https://stackoverflow.com/questions/50686419
复制相似问题