471,888 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,888 software developers and data experts.

Help, get system time with milliseconds without Timer control

jeffbroodwar
118 100+
please help me get the system's time (with milliseconds) i need it to calculate the Soap request and response time in my SOAP project. i tried to use timer but the problem is, whenever i'm invoking a method.... the timer gets stuck along with the process, meaning it always returns .01 millisecond...... timer hangs with my pc..... i need to get the system time (with milliseconds) before and after calling the webservice then compute for the difference..... PLEASE HELP ME GUYS THIS THING'S IMPORTANT TO ME !! Thanx a lot !!!!!
Feb 20 '07 #1
8 43487
hariharanmca
1,977 1GB
please help me get the system's time (with milliseconds) i need it to calculate the Soap request and response time in my SOAP project. i tried to use timer but the problem is, whenever i'm invoking a method.... the timer gets stuck along with the process, meaning it always returns .01 millisecond...... timer hangs with my pc..... i need to get the system time (with milliseconds) before and after calling the webservice then compute for the difference..... PLEASE HELP ME GUYS THIS THING'S IMPORTANT TO ME !! Thanx a lot !!!!!

use Format(Now, "HH:mm:ss:ms")
Feb 20 '07 #2
hariharanmca
1,977 1GB
use Format(Now, "HH:mm:ss:ms")
sorry, the above post is worng
Feb 20 '07 #3
jeffbroodwar
118 100+
Solved....
'Declarations :
-----------------------------------------------------------------------------------------------------------
Option Explicit

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 Declare Sub GetSystemTime Lib "kernel32" _
(lpSystemTime As SYSTEMTIME)
------------------------------------------------------------------------------------------------------------

'Function :
------------------------------------------------------------------------------------------------------------
Public Function TimeToMillisecond() As String
Dim sAns As String
Dim typTime As SYSTEMTIME

On Error Resume Next
GetSystemTime typTime
sAns = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & _
":" & typTime.wMilliseconds
TimeToMillisecond = sAns
End Function
Feb 20 '07 #4
jeffbroodwar
118 100+
guess so.... but why? i mean it goes with vb's format function right? why will it be wrong???... hmm... can you test the code that i've posted? perhaps you can help me decide what's the correct one.... and please explain to me why your post is wrong. i tested it, it's obviously wrong but what made it wrong? thanx....
Feb 20 '07 #5
hariharanmca
1,977 1GB
guess so.... but why? i mean it goes with vb's format function right? why will it be wrong???... hmm... can you test the code that i've posted? perhaps you can help me decide what's the correct one.... and please explain to me why your post is wrong. i tested it, it's obviously wrong but what made it wrong? thanx....
no, i told the post which i had post is wrong
Feb 20 '07 #6
mayhem
1
use Format(Now, "HH:mm:ss:ms")

Format(Now, "HH:mm:ss:ms")

is incorrect..... for some reason the ms is not reconised by visual basic...
I've not had time to look into it, but do simple test

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. MsgBox Format(Now, "HH:mm:ss:ms")
  3. End Sub
you will see the last 3 digits are actully seconds.....
my is "3" then the current seconds digit(s)

the API GetSytemTime Works best for current system time.... API's are always preffered
Mar 13 '07 #7
Hope this is what you wanted:
Expand|Select|Wrap|Line Numbers
  1. Public Sub DoWork()
  2.      Dim startDt as Date = Now()
  3.  
  4.      ' Do you work here
  5.  
  6.      Dim endDt as Date = Now()
  7.  
  8.      Dim tm as long = DateDiffMs(startDt, endDt)
  9.  
  10.   End Sub
  11.  
  12.  
  13.   Public Shared Function DateDiffMs(ByVal startDt As Date, ByVal endDt As Date) As Long
  14.     Dim ms As Long = DateDiff(DateInterval.Second, startDt, endDt) * 1000
  15.     If (endDt.Millisecond - startDt.Millisecond) < 0 Then
  16.       ms += 1000 - (startDt.Millisecond - endDt.Millisecond)
  17.     Else
  18.       ms += (endDt.Millisecond - startDt.Millisecond)
  19.     End If
  20.     Return ms
  21.   End Function
  22.  
Cheers!
Mar 13 '07 #8
Hope this is what you wanted:
Expand|Select|Wrap|Line Numbers
  1. Public Sub DoWork()
  2.      Dim startDt as Date = Now()
  3.      ' Do you work here
  4.      Dim endDt as Date = Now()
  5.      Dim tm as long = DateDiffMs(startDt, endDt)
  6. End Sub
  7.  
  8. Public Shared Function DateDiffMs(ByVal startDt As Date, ByVal endDt As Date) As Long
  9.     Dim ms As Long = DateDiff(DateInterval.Second, startDt, endDt) * 1000
  10.     If (endDt.Millisecond - startDt.Millisecond) < 0 Then
  11.       ms += 1000 - (startDt.Millisecond - endDt.Millisecond)
  12.     Else
  13.       ms += (endDt.Millisecond - startDt.Millisecond)
  14.     End If
  15.     Return ms
  16.   End Function
  17.  
This actually works. I have been looking for a solution to this sort of problem for some time. Funny that I never came across the "Date.Millisecond" bit, it was there all the time...

Thanks very much.
Mar 14 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by curious | last post: by
4 posts views Thread by William Bub | last post: by
10 posts views Thread by Partho Choudhury | last post: by
8 posts views Thread by marcus | last post: by
6 posts views Thread by Steve | last post: by
1 post views Thread by abhishek007p | last post: by
3 posts views Thread by Steve | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.