473,626 Members | 3,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timespan problem

hey,

when I do:

TimeSpan ts = TimeSpan.FromTi cks(System.Envi roment.TickCoun t);

ts.ToString();

I get something like this: 00:00:00.238147 4
but I want to see, how many hours, minutes....this are...

what can I do?
Nov 15 '05 #1
5 2315
Dirk Reske <_F*******@gmx. net> wrote:
when I do:

TimeSpan ts = TimeSpan.FromTi cks(System.Envi roment.TickCoun t);

ts.ToString();

I get something like this: 00:00:00.238147 4
but I want to see, how many hours, minutes....this are...

what can I do?


Look at the various properties of TimeSpan such as Hours, Minutes etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
these are allways 0

"Jon Skeet" <sk***@pobox.co m> schrieb im Newsbeitrag
news:MP******** *************** *@msnews.micros oft.com...
Dirk Reske <_F*******@gmx. net> wrote:
when I do:

TimeSpan ts = TimeSpan.FromTi cks(System.Envi roment.TickCoun t);

ts.ToString();

I get something like this: 00:00:00.238147 4
but I want to see, how many hours, minutes....this are...

what can I do?


Look at the various properties of TimeSpan such as Hours, Minutes etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Dirk Reske <_F*******@gmx. net> wrote:
these are allways 0


In that case your TimeSpan is shorter than a minute - in your example,
for instance, it's only 238 milliseconds long, so yes, the hours and
minutes values *would* be 0.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
when I do:
TimeSpan ts = TimeSpan.FromTi cks(System.Envi ronment.TickCou nt);

textBox1.Text = ts.Hours.ToStri ng() + ":" + ts.Minutes.ToSt ring() + ":" +
ts.Seconds.ToSt ring();

I get: 0:0:6 my computer is on for more than 15 hours now!!!!!

"Jon Skeet" <sk***@pobox.co m> schrieb im Newsbeitrag
news:MP******** *************** *@msnews.micros oft.com...
Dirk Reske <_F*******@gmx. net> wrote:
these are allways 0


In that case your TimeSpan is shorter than a minute - in your example,
for instance, it's only 238 milliseconds long, so yes, the hours and
minutes values *would* be 0.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
Dirk Reske <_F*******@gmx. net> wrote:
when I do:
TimeSpan ts = TimeSpan.FromTi cks(System.Envi ronment.TickCou nt);

textBox1.Text = ts.Hours.ToStri ng() + ":" + ts.Minutes.ToSt ring() + ":" +
ts.Seconds.ToSt ring();

I get: 0:0:6 my computer is on for more than 15 hours now!!!!!


The problem is in what is meant by "tick" here. From
System.Environm ent.TickCount:

<quote>
Property Value
A 32-bit signed integer containing the amount of time in milliseconds
that has passed since the last time the computer was started.
</quote>

Note the "in milliseconds" bit.

Now from TimeSpan.FromTi cks:
<quote>
Remarks
This is a convenience method with the same behavior as the TimeSpan
constructor.
</quote>

the constructor in question is TimeSpan(long), which has this
information:

<quote>
Parameters
ticks
A time period expressed in 100-nanosecond units.
</quote>

So Environment.Tic kCount is giving it in milliseconds, and you're then
constructing a TimeSpan with that number of 100-nanosecond units.
Instead of that, if you use TimeSpan.FromMi lliseconds() you'll get a
much more appropriate figure.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

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

Similar topics

2
21050
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 agent talks about 5 hours per day, this comes out to about 150 hours of talk time per month. Fine. But, the DateTime and TimeSpan format strings will only output hours from 0-23. I need something that will output time as such: 150:0:0 to...
1
1375
by: Rosanne | last post by:
I'm sure there's an easy solution to this that I am just not thinkin of. I am trying to get the total minutes between 2 times. It work fine except when the ending time crosses over midnight. For instance I am trying to get the total minutes between 11:59 PM and 12:09 AM. The subtract method on the TimeSpan object returns a crazy negativ number. I can't seem to find a work around. Thanks so much in advance! --
10
1913
by: scorpion53061 | last post by:
What I thought would be pretty easy has turned out not to be. I have three variables. Actiontime is formatted as 08/11/2004 11:03PM Actiontime JobStreamStart (11:00:00PM) JobStreamEnd (2:00:00AM) If (Format(CDate(ActionTime), "t") >= JobStreamStart AND (Format(CDate(ActionTime), "t") < jobstreamend Then
6
4568
by: richardkreidl | last post by:
I am using the code below to notify the user to do different tasks at certain times of the day: Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Select Case Now().ToString("hh:mm:ss") Case "08:30:00" MsgBox("Do this") Case "12:30:00" MsgBox("Do that")
7
5532
by: jack | last post by:
Hi all i have just begin csharp have a problem in saving time in database I have to comboboxex in form one containing hours from 0 to 23 and another containig minutes from 0 to 59 the problem is saving it in to the database I want to save only the time in to the database but i dont know how to convert it wether to use timespan to use datetime datatype
13
2137
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 will fall somewhere between a Start & End time Further more, there will be Break & Lunch times between Start & End. Example... Start 08:00 Break start 10:30
5
1992
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
4
6235
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 HOUR .... if i try to Call A.Select( " HOUR '10:30:00' " ) i receive an error ( cannot compare TimeSpan with String ...) if i try to call A.Select ( " HOUR 10:30:00 " ) i receive an error ( invalid token : )
5
1630
by: | last post by:
Why is it that: DateTime start = DateTime.Parse("1:00 AM"); DateTime stop = DateTime.Parse("2:30 AM"); TimeSpan ts = stop - start; Response.Write(ts.Minutes.ToString()); Produces 30, not 90? How do I return the exact number of minutes between 2 times?
0
8641
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.