Get CurrentDate into TimeSpan

B

Ben

Hi

I have to run a process in an VB ASP .net.

I have to measure how long the process has taken in seconds/miliseconds.

Seeing as the Date datatype does not handle miliseconds it seems TimeSpan is
the correct datatype to use.

How can I get the current time into timespan?

Is there a similar method as using a date variable e.g. dteDate = Now()

Thanks
B
 
C

Cor Ligthert [MVP]

Ben,

You can use environment.tickcount to get a start millisecond and the end
millisecond. That is for me the most easiest one to test. In 2.0 is as well
a special stopwatch class for that.

Be aware that in a PC the milliseconds are never secure.

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

Ben said:
I have to measure how long the process has taken in seconds/miliseconds.

Seeing as the Date datatype does not handle miliseconds it seems TimeSpan
is
the correct datatype to use.

How can I get the current time into timespan?

Is there a similar method as using a date variable e.g. dteDate = Now()


'TimeSpan' only represents a certain period of time.

You may want to use this class in order to get more accurate results:

<URL:http://www.mentalis.org/soft/class.qpx?id=8>
 
R

Ross Presser

Hi

I have to run a process in an VB ASP .net.

I have to measure how long the process has taken in seconds/miliseconds.

Seeing as the Date datatype does not handle miliseconds it seems TimeSpan is
the correct datatype to use.

The date datatype certainly does include milliseconds. But you are
correct, TimeSpan is the correct date type to use to measure an elapsed
span of time.

The rest of your post is asking the wrong questions.

Here is how to measure how long something takes:

dim StartTime as DateTime = Now()

' do whatever it is that we're timing

dim FinishTime as DateTime = Now()
dim ElapsedTime as TimeSpan = FinishTime.Subtract(StartTime)
Msgbox("Total time taken: " & ElapsedTime.ToString("ss.ff")
 
A

Armin Zingler

Ben said:
Hi

I have to run a process in an VB ASP .net.

I have to measure how long the process has taken in
seconds/miliseconds.

Seeing as the Date datatype does not handle miliseconds it seems
TimeSpan is the correct datatype to use.

How can I get the current time into timespan?

Is there a similar method as using a date variable e.g. dteDate =
Now()


The resolution of the Date date type is 100 nanoseconds, but the actual
resolution of Now() is 55 or 10 milliseconds, depending on the OS.

I'd use Environment.Tickcount.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top