在vb中怎样显示毫秒?

2025-07-26 10:04:10
推荐回答(4个)
回答1:

使用GetTickCount
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

起点和终点各调用一次,取时间差,以毫秒为单位

t=GetTickCount
'……
'……
'你的代码
'……
'……
t=GetTickCount-t

最后得出来的t就是毫秒为单位的

回答2:

Function GetMiniTime() As String
Dim Tss As Single, HM As Integer, SS As Integer, MM As Integer, HH As Integer
Tss = Timer() * 1000
HM = Tss Mod 1000 '得到毫秒
Tss = Tss \ 1000 '总秒数
HH = Tss \ 3600 '得到小时
Tss = Tss Mod 3600 '总分钟数
MM = Tss \ 60 '得到分钟
SS = Tss Mod 60 '得到秒
GetMiniTime = Format(HH, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "000")
End Function

测试:
Private Sub Form_Load()
Me.Caption = GetMiniTime
End Sub

回答3:

建一个Timer1.
代码如下。
============
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 Type
Private Sub Form_Load()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
Dim t As SYSTEMTIME
GetLocalTime t
Cls
Print DateSerial(t.wYear, t.wMonth, t.wDay) & " " & TimeSerial(t.wHour, t.wMinute, t.wSecond) & "." & t.wMilliseconds
End Sub

回答4:

60000毫秒=一分