两种方式自己选用
创新互联建站是一家专注于成都网站设计、做网站与策划设计,德城网站建设哪家好?创新互联建站做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:德城等地区。德城做网站价格咨询:13518219792
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = DateTime.Today.Year()
s = s DateTime.Today.Month()
s = s DateTime.Today.Day()
s = s DateTime.Now.Hour()
s = s DateTime.Now.Minute()
s = s DateTime.Now.Second()
MsgBox(s, vbDefaultButton1, Now())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String
s = Format(Now(), "yyyymmddhhmmss")
MsgBox(s, vbYes, Now())
End Sub
用TIMER控件调用NOW函数,可取得系统的日期和时间:
Private Sub Timer1_Timer()
Text1 = Now
End Sub
vb中获取系统当前的时间用函数 now() 就可以。另外还有相关的时间 date() time()
now()获取系统当前日期和时间,如:2015-12-12 22:23:34
time()获取系统的时间,如:22:23:34不显示当前日期
date()获得系统的日期,如:2015-12-12
Private Sub Command1_Click()
MsgBox Now()
MsgBox Time()
MsgBox Date
End Sub
可以访问注册表HKEY_CURRENT_USER\Control Panel\International下面的一些键值
如sShortDate键值表示的是短日期sLongDate表示的是长日期
中文下的短日期是 yyyy-M-d
中文下的长日期是 yyyy'年'M'月'd'日'
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
上面是获取月份以及天数
'======================
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位数"
Else
c = "2位数"
End If
If b 0 AndAlso b 10 Then
d = "1位数"
Else
d = "2位数"
End If
MessageBox.Show(c)
MessageBox.Show(d)
End Sub
这个是获取位数的
用日期函数day()可获得当前日期,time()可获得当前系统时间.
dim CurDay as string
dim CurTime as string
curday=day()
curtime=time()
Label1.Caption = Date
就能在Label16显示当前日期
now 这个函数可以获得当前系统时间(包括年月日,小时分钟秒)
而
year()
month()
day()
等等则可以从now返回的值中分别提取年,月,日的信息