Board index » Visual Studio » How to write out current time including milliseconds?
|
LuxembourgITAnalyst
|
|
LuxembourgITAnalyst
|
How to write out current time including milliseconds?
Visual Studio329
I tried format$(now, "hhh:mm:ss.xxx"), where xxx is pretty much any letter out there all to no avail. How to write out current time including milliseconds in the format specified? - |
| Dmitriy
Registered User |
Wed Apr 09 00:22:37 CDT 2008
Re:How to write out current time including milliseconds?"Frank Rizzo" <none@none.net>wrote in message QuoteI tried format$(now, "hhh:mm:ss.xxx"), where xxx is pretty much any letter for better precision. The following sample is from API-Guide 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() 'KPD-Team 1998 'URL: www.allapi.net/">www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net Dim MyTime As SYSTEMTIME 'Set the graphical mode to persistent Me.AutoRedraw = True 'Get the local time GetLocalTime MyTime 'Print it to the form Me.Print "The Local Date is:" & MyTime.wMonth & "-" & MyTime.wDay & "-" & MyTime.wYear Me.Print "The Local Time is:" & MyTime.wHour & ":" & MyTime.wMinute & ":" & MyTime.wSecond & "." & MyTime.wMilliseconds End Sub Dmitriy. - |
| Peter
Registered User |
Wed Apr 09 07:31:30 CDT 2008
Re:How to write out current time including milliseconds?
"Dmitriy Antonov" <antonovdima@netzero.net_not_for_spam>wrote in message
Quote
Regards, Peter T - |
| Dmitriy
Registered User |
Wed Apr 09 09:21:20 CDT 2008
Re:How to write out current time including milliseconds?"Peter T" <peter_t@discussions>wrote in message Quote"Dmitriy Antonov" <antonovdima@netzero.net_not_for_spam>wrote in message the Timer function is updated 18+ times per second. The sample I provided is not the best one either but I guess it is still more accurate then the Timer function. If highest possible precision is interesting then you may look at multimedia timers - there are plenty of info about it on the Internet. Dmitriy. - |
| Mike
Registered User |
Wed Apr 09 09:41:08 CDT 2008
Re:How to write out current time including milliseconds?
"Peter T" <peter_t@discussions>wrote in message
QuoteCuriosity, is the API ever more accurate than simply 'Timer'. methods is particularly accurate, and certainly not to within a few milliseconds, even if your machine is regularly updated from a reliable time source. But if you mean resolution, then the multimedia timer will give you a resolution of about one millisecond and QueryFormanceCounter will give you a resolution of about one micosecond, provided you take care to ignore the occasional spurious timing it will throw up very occasionally on some systems under certain conditions. Mike - |
| Peter
Registered User |
Wed Apr 09 09:54:52 CDT 2008
Re:How to write out current time including milliseconds?
"Dmitriy Antonov" <antonovdima@netzero.net_not_for_spam>wrote in message
Quote
for me. Enough for many purposes but not milliseconds. Public Declare Function GetTickCount Lib "kernel32" () As Long Sub test() Dim tmr As Single, tmrStop As Single Dim t1 As Long, t2 As Long tmrStop = Timer + 2 Do While Timer < tmrStop If tmr <>Timer Then tmr = Timer t2 = GetTickCount Debug.Print tmr, t2, Int(1000 / (t2 - t1)) ' updates / sec t1 = t2 End If Loop about 18 times per second Regards, Peter T - |
| Peter
Registered User |
Wed Apr 09 10:31:04 CDT 2008
Re:How to write out current time including milliseconds?
"Mike Williams" <mikea@whiskyandCoke.com>wrote in message
Quote"Peter T" <peter_t@discussions>wrote in message more accurate than 'Timer' to return "current time" or fractional seconds since midnight. In a light test they both seem about the same, ie update about 18x per second. Regards, Peter T - |
| Ken
Registered User |
Wed Apr 09 10:58:46 CDT 2008
Re:How to write out current time including milliseconds?
"Peter T" <peter_t@discussions>wrote in message
Quote"Mike Williams" <mikea@whiskyandCoke.com>wrote in message timing sections of your app, though (like do something, wait 5 seconds, do something else)... better stay away from Timer, since it rolls over at midnight. -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. In Loving Memory - www.vbsight.com/Remembrance.htm">www.vbsight.com/Remembrance.htm - |
| Mike
Registered User |
Wed Apr 09 14:34:34 CDT 2008
Re:How to write out current time including milliseconds?
"Peter T" <peter_t@discussions>wrote in message
QuoteIn a light test they both seem about the same, ie timeBeginPeriod 1 before you start using it, and it returns the number of milliseconds since Windows was last started. You could use that in conjunction with he system time to give you your desired resolution. Mike - |
