Help, get system time with milliseconds without Timer control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeffbroodwar
    New Member
    • Oct 2006
    • 118

    Help, get system time with milliseconds without Timer control

    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 !!!!!
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by jeffbroodwar
    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:m s")

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      Originally posted by hariharanmca
      use Format(Now, "HH:mm:ss:m s")
      sorry, the above post is worng

      Comment

      • jeffbroodwar
        New Member
        • Oct 2006
        • 118

        #4
        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 TimeToMilliseco nd() As String
        Dim sAns As String
        Dim typTime As SYSTEMTIME

        On Error Resume Next
        GetSystemTime typTime
        sAns = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & _
        ":" & typTime.wMillis econds
        TimeToMilliseco nd = sAns
        End Function

        Comment

        • jeffbroodwar
          New Member
          • Oct 2006
          • 118

          #5
          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....

          Comment

          • hariharanmca
            Top Contributor
            • Dec 2006
            • 1977

            #6
            Originally posted by jeffbroodwar
            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

            Comment

            • mayhem
              New Member
              • Feb 2007
              • 1

              #7
              Originally posted by hariharanmca
              use Format(Now, "HH:mm:ss:m s")

              Format(Now, "HH:mm:ss:m s")

              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

              Code:
              Private Sub Command1_Click()
              MsgBox Format(Now, "HH:mm:ss:ms")
              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

              Comment

              • GoHokies95
                New Member
                • Mar 2007
                • 3

                #8
                Hope this is what you wanted:
                Code:
                Public Sub DoWork()
                     Dim startDt as Date = Now()
                
                     ' Do you work here
                
                     Dim endDt as Date = Now()
                 
                     Dim tm as long = DateDiffMs(startDt, endDt)
                    
                  End Sub
                
                
                  Public Shared Function DateDiffMs(ByVal startDt As Date, ByVal endDt As Date) As Long
                    Dim ms As Long = DateDiff(DateInterval.Second, startDt, endDt) * 1000
                    If (endDt.Millisecond - startDt.Millisecond) < 0 Then
                      ms += 1000 - (startDt.Millisecond - endDt.Millisecond)
                    Else
                      ms += (endDt.Millisecond - startDt.Millisecond)
                    End If
                    Return ms
                  End Function
                Cheers!

                Comment

                • kaihora
                  New Member
                  • Mar 2007
                  • 1

                  #9
                  Originally posted by GoHokies95
                  Hope this is what you wanted:
                  Code:
                  Public Sub DoWork()
                       Dim startDt as Date = Now()
                       ' Do you work here
                       Dim endDt as Date = Now()
                       Dim tm as long = DateDiffMs(startDt, endDt)
                  End Sub
                  
                  Public Shared Function DateDiffMs(ByVal startDt As Date, ByVal endDt As Date) As Long
                      Dim ms As Long = DateDiff(DateInterval.Second, startDt, endDt) * 1000
                      If (endDt.Millisecond - startDt.Millisecond) < 0 Then
                        ms += 1000 - (startDt.Millisecond - endDt.Millisecond)
                      Else
                        ms += (endDt.Millisecond - startDt.Millisecond)
                      End If
                      Return ms
                    End Function
                  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.Milliseco nd" bit, it was there all the time...

                  Thanks very much.

                  Comment

                  Working...