這樣:
站在用戶的角度思考問題,與客戶深入溝通,找到魯?shù)榫W(wǎng)站設(shè)計(jì)與魯?shù)榫W(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋魯?shù)榈貐^(qū)。
Private?Sub?Button1_Click(sender?As?Object,?e?As?EventArgs)?Handles?Button1.Click
Dim?leapyears()?As?Integer?=?GetLeapYears(2000,?2100)
Dim?str?As?String
Try
Dim?count?As?Integer?=?UBound(leapyears)?+?1
str?=?"閏年個(gè)數(shù):"?+?count.ToString
For?i?=?0?To?UBound(leapyears)
str?+=?"?"?+?leapyears(i).ToString
Next
TextBox1.Text?=?str
Catch?ex?As?Exception?
End?Try
End?Sub
'''?summary
'''?獲取指定年份區(qū)間中所有閏年組成的數(shù)組
'''?/summary
'''?param?name="StartYear"起始年份/param
'''?param?name="EndYear"結(jié)束年份/param
'''?returns/returns
'''?remarks/remarks
Private?Function?GetLeapYears(StartYear?As?Integer,?EndYear?As?Integer)?As?Integer()
Dim?leapyears()?As?Integer?=?Nothing
Dim?index?As?Integer?=?0
For?i?=?StartYear?To?EndYear
If?(i?Mod?400?=?0)?Or?(i?Mod?4?=?0?And?i?Mod?100??0)?Then
ReDim?Preserve?leapyears(index)
leapyears(index)?=?i
index?+=?1
End?If
Next
Return?leapyears
End?Function
擴(kuò)展資料:
注意事項(xiàng)
DateSerial返回包含指定的年、月、日的 Variant (Date)。
語法:DateSerial(year, month, day)
Private Function MonthToLeapYear(ByVal Yea As Integer) As Boolean
MonthToLeapYear = Day(DateSerial(Yea, 2, 29)) = 29
End Function
Private Sub Command1_Click()
If Len(Text1.Text) = 4 Then
? If MonthToLeapYear(Text1.Text) = True Then
? ? ? Print Text1.Text "年是閏年"
? Else
? ? ? Print Text1.Text "年是平年"
? End If
Else
?Print "錯(cuò)誤:請(qǐng)輸入正確的年份!"
End If
End Sub
在VB.NET中進(jìn)行日期處理時(shí),避免手工判斷或計(jì)算是個(gè)好主意,因?yàn)槭止び?jì)算由于代碼的質(zhì)量問題可能不準(zhǔn)確??梢允褂?NET提供的類的功能進(jìn)行日期處理。
例如,如果需要判斷給定的某年是否閏年,可以使用VB.NET的IsLeapYear函數(shù)。下面是如何使用該函數(shù)的一個(gè)例子:
Private Sub LeapYearCheck()
Dim bLeapYear AsBoolean
bLeapYear = Date.IsLeapYear(Now.Year)
MessageBox.Show(bLeapYear)
bLeapYear = Date.IsLeapYear(2004)
MessageBox.Show(bLeapYear)
End Sub
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '獲得當(dāng)前日期字符串
Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '當(dāng)前日期轉(zhuǎn)換成DateTime
Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '獲得當(dāng)前日期是星期幾
Dim differadd As Integer = 1 - ThisWeekDay '相差的天數(shù)(星期1與當(dāng)前星期幾相差的天數(shù))
Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)
Dim MyYear As Integer = Format(Now, "yyyy") '獲取當(dāng)前日期的年份
Dim MyMonth As Integer = Format(Now, "MM") '獲取當(dāng)前日期的月份
Dim MyDay As Integer = Format(Now, "dd") '獲取當(dāng)前日期是幾號(hào)
Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)
Dim Yourday As DateTime = MyToday.Add(MyAdd)
MsgBox("本周星期一的日期是:" Yourday)
不是 有 函數(shù)嘛?
now() 就是 吧
取得 后 再 分離出你所需的,分別賦值 就行了,當(dāng)然 還是 有 函數(shù)的