Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '獲得當(dāng)前日期字符串
創(chuàng)新互聯(lián)公司是專(zhuān)業(yè)的東洲網(wǎng)站建設(shè)公司,東洲接單;提供成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行東洲網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
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)
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)
不是 有 函數(shù)嘛?
now() 就是 吧
取得 后 再 分離出你所需的,分別賦值 就行了,當(dāng)然 還是 有 函數(shù)的
這個(gè)非常簡(jiǎn)單的.
用時(shí)間函數(shù),然后用文字轉(zhuǎn)下.就行了.
我現(xiàn)在用的是.NET,不太清楚VB6.0是不是了.
你先用 日期里的Month 把一個(gè)時(shí)間中的月份取出來(lái) .
再用Format轉(zhuǎn)化下文本格式, 比如用的月份是 mon 那么就是: Format(mon,"00")
這樣就行了. "00" 表示的是以?xún)晌粩?shù)字顯示,沒(méi)到兩位的以0補(bǔ).
如果是在EXCEL宏里,那就直接給你寫(xiě)了吧:
Dim Mon1 As String
Dim Mon2 As String
Mon1 = VBA.Month(VBA.Now)
Mon2 = Format(Mon1, "00")
這里的Mon2 就是 你的那個(gè)月份.
用日期函數(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返回的值中分別提取年,月,日的信息