Dirk Reske said:
when I do:
TimeSpan ts = TimeSpan.FromTicks(System.Environment.TickCount);
textBox1.Text = ts.Hours.ToString() + ":" + ts.Minutes.ToString() + ":" +
ts.Seconds.ToString();
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.Environment.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.FromTicks:
<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.TickCount 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.FromMilliseconds() you'll get a
much more appropriate figure.