加入以下代码:
Private Sub Form_Load()Text1.Text = NowTimer1.Enabled = TrueTimer1.Interval = 1000Text1.Text = NowEnd Sub扩展资料:VB获取系统当前时间并格式化输出用到的函数:
Date函数:返回系统的日期实例:
Private Sub Form_Load()'设置同步时间显示Timer1.Interval = 1000Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()Label2.Caption = Format(Now, "hh:mm:ss") '获取当前时间Label4.Caption = Format(Now, "yyyy-mm-dd") '获取当前日期Label6.Caption = Format(Now, "yyyy-mm-dd hh:mm:ss") '日期和时间End Sub