473,406 Members | 2,356 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,406 software developers and data experts.

Get CurrentDate into TimeSpan

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
Nov 23 '05 #1
5 3379
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
Nov 23 '05 #2
Secure = exact
Nov 23 '05 #3
"Ben" <Be*@Newsgroups.microsoft.com> schrieb:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #4
On Mon, 21 Nov 2005 18:25:17 -0000, Ben wrote:
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")
Nov 23 '05 #5
"Ben" <Be*@Newsgroups.microsoft.com> schrieb
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

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
3
by: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
10
by: Charles Law | last post by:
If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can't find it.
2
by: ucasesoftware | last post by:
i translate a C# funtion to VB.NET and i have this : Shared Function isAllDay(ByVal ap As Appointment) As Boolean Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap.DateEnd.TimeOfDay =...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
5
by: style | last post by:
Hello In my custom configuration section, I'd like to specify an interval attribute which specifies an interval in milliseconds. I think it would be very comfortable to get this value directly...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.