不是 有 函數(shù)嘛?
創(chuàng)新互聯(lián)提供網(wǎng)站制作、成都網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì),品牌網(wǎng)站設(shè)計(jì),1元廣告等致力于企業(yè)網(wǎng)站建設(shè)與公司網(wǎng)站制作,10多年的網(wǎng)站開(kāi)發(fā)和建站經(jīng)驗(yàn),助力企業(yè)信息化建設(shè),成功案例突破上1000+,是您實(shí)現(xiàn)網(wǎng)站建設(shè)的好選擇.
now() 就是 吧
取得 后 再 分離出你所需的,分別賦值 就行了,當(dāng)然 還是 有 函數(shù)的
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ù)day()可獲得當(dāng)前日期,time()可獲得當(dāng)前系統(tǒng)時(shí)間.
dim CurDay as string
dim CurTime as string
curday=day()
curtime=time()
Label1.Caption = Date
就能在Label16顯示當(dāng)前日期
now 這個(gè)函數(shù)可以獲得當(dāng)前系統(tǒng)時(shí)間(包括年月日,小時(shí)分鐘秒)
而
year()
month()
day()
等等則可以從now返回的值中分別提取年,月,日的信息
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Short = Date.Now.Month
Dim b As Short = Date.Now.Day
MessageBox.Show(a)
MessageBox.Show(b)
End Sub
上面是獲取月份以及天數(shù)
'======================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Short = Date.Now.Month
Dim b As Short = Date.Now.Day
Dim c, d As String
If a 0 AndAlso a 10 Then
c = "1位數(shù)"
Else
c = "2位數(shù)"
End If
If b 0 AndAlso b 10 Then
d = "1位數(shù)"
Else
d = "2位數(shù)"
End If
MessageBox.Show(c)
MessageBox.Show(d)
End Sub
這個(gè)是獲取位數(shù)的
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)