发布网友 发布时间:2022-04-22 21:34
共3个回答
热心网友 时间:2023-10-25 04:45
VB写的 参考一下
Dim str As String = "2010-07-12"
Dim year As String = str.Substring(0, 4)
Dim y As Integer = CInt(year) '获取年
If CInt(y Mod 4 = 0 And y Mod 100 <> 0) Or y Mod 400 = 0 Then '闰年
Dim M As Integer = CInt(Mid(6, 2)) '获取月
Dim d As Integer = CInt(Mid(9, 2)) '获取天
Dim zhou As Integer '周
Select Case M
Case 1
If d Mod 7 = 0 Then
zhou = d / 7
Else
zhou = d / 7 + 1
End If
Case 2
If (d + 31) Mod 7 = 0 Then
zhou = (d + 31) / 7
Else
zhou = (d + 31) / 7 + 1
End If
Case 3
If (d + 31 + 28) Mod 7 = 0 Then '+31+28意思是加前面的第一个月31天第二个月28天,下面类似
zhou = (d + 31 + 28) / 7
Else
zhou = (d + 31 + 28) / 7 + 1
End If
Case 4
'
'
'
'
End Select
Else '不是闰年
Dim M As Integer = CInt(Mid(6, 2)) '获取月
Dim d As Integer = CInt(Mid(9, 2)) '获取天
Dim zhou As Integer '周
Select Case M
Case 1
If d Mod 7 = 0 Then
zhou = d / 7
Else
zhou = d / 7 + 1
End If
Case 2
If (d + 31) Mod 7 = 0 Then
zhou = (d + 31) / 7
Else
zhou = (d + 31) / 7 + 1
End If
Case 3
If (d + 31 + 29) Mod 7 = 0 Then '这个是和闰年的区别 +29
zhou = (d + 31 + 29) / 7
Else
zhou = (d + 31 + 29) / 7 + 1
End If
Case 4
'
'
'
'
End Select
End If
热心网友 时间:2023-10-25 04:46
excel吗
热心网友 时间:2023-10-25 04:46
你至少先说你用的啥语言……
这个先做闰年判断再算出天数然后div 7不就完了么,没啥难的啊……