问题描述
我的周数计算错误.
我有两个下拉值.
第一值:31-2011(周和年)
第二值:1-2013(周和年)..
当我计算这两者的持续时间时,我得到的总周数为"104700".
实际上,我对于这些值的持续时间是错误的.
我只需要"75"周即可.
因为,31-2011年将有52周(2011年= 21周(31周-52周))
2012 =我们将有53周(所以21 + 53周)
2013 =将有1周(因此,22 + 53 + 1)= 75 ..
我的代码有什么问题..?我需要更改的地方.
查看我的代码
Hi,
I am getting wrong calculation for the count of weeks.
I have two dropdown values.
First values : 31-2011 (Week & Year)
Second Values : 1-2013 (Week & Year)..
When i calculate the duration of these two, i am getting total Weeks as "104700".
Actually i am getting wrong duration for these values.
I need to get "75" weeks only.
Because, 31-2011 will have 52 weeks (for 2011 = 21 Weeks (31week -52week))
2012 = We will have 53 Weeks (so 21+53 Weeks)
2013 = will have 1 Week ( So, 22+53+1) = 75..
What is the problem in my code..? where i need to change.
See my code
Dim parts1 As String() = drpStweek.SelectedItem.ToString().Split("-")
Dim parts2 As String() = drpEdweek.SelectedItem.ToString().Split("-")
If Integer.TryParse(parts1(0), week1) AndAlso Integer.TryParse(parts1(1), year1) AndAlso Integer.TryParse(parts2(0), week2) AndAlso Integer.TryParse(parts2(1), year2) Then
If year1 <= year2 Then
If year1 = year2 Then
Duration = week2 - week1
Else
Duration += (52 - week1) + week2
If year2 - year1 > 1 Then
Duration += (52 * year2 - year1)
End If
End If
End If
End If
推荐答案
这篇关于星期数计算错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!