473,372 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 43974
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

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

Similar topics

4
by: curious | last post by:
I am new to VB.NET and I need help in using timer control. Here is the scenario. I have 3 labels (label 1, label2, label 3), and a start button, all vertically aligned on the form. Using a...
4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
10
by: Partho Choudhury | last post by:
Hi all: I need to add a snippet which access the system time (upto atleast milliseconds) using ANSI std. C++. I cannot use MFC and Win32 APIs in my program for now for various reasons. Is there...
8
by: marcus | last post by:
Is their a method in c++ or c that gives me the system time in milliseconds or higher resolution? I need it to be platform independent. Today I use timeGetTime which is windows specific. thanks
6
by: Steve | last post by:
I am working on a emulator and need to have time based events. I've tried to use the timer control and discovered that it runs waaaaaaay slow. I set the tick frequency to 1, then in the tick...
1
by: abhishek007p | last post by:
HI, i am using visual web developer for .net 2.0. does .NET 2.0 comes with a timer control, i was unable to find it in the IDE, where is it ? thanks, Abhishek
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
16
by: neelsfer | last post by:
I need to add milliseconds to this finishtime of race !!! = Format(Now(), "General Date") Start code for race also in milliseconds !!! = Format(Now(), "General Date") I will then subtract it...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.