毫秒看不出来
timer1.Interval=100Private Sub Timer1_Timer()
Static OldSec As Integer
Static SmallSec As Integer
ADDNum = 100
SmallSec = SmallSec + ADDNum
If Second(Time) = OldSec Then'校对
SmallSec = 0
End If
Label1.Caption = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time) & ":" & SmallSec / 100
OldSec = Second(Time)
End Sub
timer1.Interval=100Private Sub Timer1_Timer()
Static OldSec As Integer
Static SmallSec As Integer
ADDNum = 100
SmallSec = SmallSec + ADDNum
If Second(Time) = OldSec Then'校对
SmallSec = 0
End If
Label1.Caption = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time) & ":" & SmallSec / 100
OldSec = Second(Time)
End Sub
timer1.Interval=100Private Sub Timer1_Timer()
label1.caption= now
end sub
得到“小时:分钟:秒”的字符串
毫秒时不容易得到的!
最多了吧?
还有其他的方法么?
不知道API该如何定义:(
Timer控件要Enable,触发频率设为100
private sub Timer1_Timer()
me.caption = cstr(Timer.Time)
end sub
GetSystemTime返回UTC时间,GetLocalTime返回当地时间。
如下例:Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End TypePrivate Sub Timer1_Timer()
Dim s As String
Dim sys As SYSTEMTIME
GetSystemTime sys ‘或者 GetLocalTime sys
s= CStr(sys.wHour) + ":" + CStr(sys.wMinute) + ":" + CStr(sys.wSecond) + ":" + CStr(sys.wMilliseconds)
‘ 或者s = Time$ + " : " + CStr(sys.wMilliseconds) Label1.Caption = s
End Sub详细信息请参考以下链接:
GetSystemTime
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/time_56p1.asp
GetLocalTime
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/time_7rj9.asp- 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
private sub timer_time()
i=i+1
if i>10 then
i=0
end if
label1.caption=now
label1.caption=label1.caption+":"&i
end sub