Discussion:
Systemzeit in Millisekunden
(zu alt für eine Antwort)
Oliver Otto
2004-02-26 10:04:33 UTC
Permalink
Hallo Leute,

hab mal eine Frage. Ich will die Systemzeit in Millisekunden mit Hilfe von
VBA ermitteln. Dazu benutze ich die API Funktion:

Public Declare Function timeGetTime Lib "winmm.dll" () As Long

Diese liefert mir leider nur die Zeit, formatiert in Millisekunden. Ich
brauche sie aber in dem Format: yyyy/m/d/h/mm/ss/mmmm also z.B.:
2003-12-05-10.40.54.623949

Kann mir da jemand weiterhelfen?

Vielen Dank.

Oliver
Josef Poetzl
2004-02-26 10:16:04 UTC
Permalink
Hallo!
Post by Oliver Otto
hab mal eine Frage. Ich will die Systemzeit in Millisekunden mit Hilfe von
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
Diese liefert mir leider nur die Zeit, formatiert in Millisekunden. Ich
2003-12-05-10.40.54.623949
Schreib Dir eine kleine Hilfsfunktion, welche Dir einen String mit dem
gewünschten Format zurückliefert.

Ich hab so etwas in meiner Beipiel-mdb "Stoppuhr" gemacht.
(findest Du im Downloadbereich von http://access.joposol.com/ )

Code-Auszug:
curTimeSec = HF_mRound(Me.Time / 1000, intMSecDigits)
strTimeString = Format(TimeSerial(0, 0, Fix(curTimeSec)), strSecFormatString)
If intMSecDigits > 0 Then
strTimeString = strTimeString & _
Format(curTimeSec - Fix(curTimeSec), "." & _
String(intMSecDigits, "0"))
End If

mfg
Josef
--
EPT: (Access Error Prevention Table) http://access.joposol.com/
FAQ: (Access-FAQ von Karl Donaubauer) http://www.donkarl.com/
Oliver Otto
2004-02-26 13:16:06 UTC
Permalink
Post by Josef Poetzl
curTimeSec = HF_mRound(Me.Time / 1000, intMSecDigits)
strTimeString = Format(TimeSerial(0, 0, Fix(curTimeSec)),
strSecFormatString)
Post by Josef Poetzl
If intMSecDigits > 0 Then
strTimeString = strTimeString & _
Format(curTimeSec - Fix(curTimeSec), "." & _
String(intMSecDigits, "0"))
End If
Hallo,

vielen Dank für die Idee. Anscheinend klappt aber was nicht richtig. Sehe
ich das richtig, dass "TimeGetTime" die Systemzeit in Millisekunden liefert?
Falls ja, müsste doch "TimeSerial(0, 0, TimeGetTime / 1000)" die Zeit in
"hh:mm:ss" liefern? Das macht es aber nicht, die Anzeige der Form "hh:mm:ss"
stimmt zwar, aber es ist nicht die richtige Zeit. Im Windows ist aber die
richtige Zeit eingestellt.

Kannst Du mir helfen?

Oliver
Oliver Otto
2004-02-26 13:55:01 UTC
Permalink
Post by Oliver Otto
vielen Dank für die Idee. Anscheinend klappt aber was nicht richtig. Sehe
ich das richtig, dass "TimeGetTime" die Systemzeit in Millisekunden liefert?
Falls ja, müsste doch "TimeSerial(0, 0, TimeGetTime / 1000)" die Zeit in
"hh:mm:ss" liefern? Das macht es aber nicht, die Anzeige der Form "hh:mm:ss"
stimmt zwar, aber es ist nicht die richtige Zeit. Im Windows ist aber die
richtige Zeit eingestellt.
Sorry, hab mich unklar ausgedrückt. Ich benötige die Uhrzeit mit
Millisekunden. Hast Du eine Idee?

Gruss

Oliver
Josef Poetzl
2004-02-26 16:13:03 UTC
Permalink
Hallo!
Post by Oliver Otto
Sorry, hab mich unklar ausgedrückt. Ich benötige die Uhrzeit mit
Millisekunden. Hast Du eine Idee?
Wie wäre es damit:

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 Function getLocalTimeMS() As String

Dim typSystemZeit As SYSTEMTIME
GetLocalTime typSystemZeit
getLocalTimeMS = Format(typSystemZeit.wHour, "00") & ":" & _
Format(typSystemZeit.wMinute, "00") & ":" & _
Format(typSystemZeit.wSecond, "00") & "," & _
Format(typSystemZeit.wMilliseconds, "000")

End Function

mfg
Josef
--
EPT: (Access Error Prevention Table) http://access.joposol.com/
FAQ: (Access-FAQ von Karl Donaubauer) http://www.donkarl.com/
Oliver Otto
2004-02-27 10:03:51 UTC
Permalink
Post by Josef Poetzl
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 Function getLocalTimeMS() As String
Dim typSystemZeit As SYSTEMTIME
GetLocalTime typSystemZeit
getLocalTimeMS = Format(typSystemZeit.wHour, "00") & ":" & _
Format(typSystemZeit.wMinute, "00") & ":" & _
Format(typSystemZeit.wSecond, "00") & "," & _
Format(typSystemZeit.wMilliseconds, "000")
End Function
Vielen Dank.

Funktioniert so, wie ich es wollte.

Oliver

Loading...