Reputation: 776
I have to transform my Stopwatch "Variable" into seconds ?
Stopwatch czasAlg = new Stopwatch();
czasAlg.Start();
//Do semothing
czasAlg.Stop();
Decimal Tn = czasAlg.ElapsedMilliseconds/(decimal)n;
Upvotes: 18
Views: 52067
Reputation: 233
Instead of using math and multiplying/diving like this: seconds (60) * 1000 = 60000, use TimeSpan instead, it's using bit operations, and due to it has a minimum cost of performance.
int sixtyThousandsMillisecondsInSeconds = (int)TimeSpan.FromMilliseconds(60000).TotalSeconds;
// Outputs 60
// 1 min (60 seconds) in milliseconds = 60000 (i.e 60 * 1000)
int sixtySecondsInMilliseconds = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;
// Outputs 60000
int sixtyThousendsMillisecondsInSeconds = (int)TimeSpan.FromMilliseconds(60000).TotalSeconds;
sixtyThousendsMillisecondsInSeconds.Dump();
int sixtySecondsInMilliseconds = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;
sixtySecondsInMilliseconds.Dump();
60
60000
Upvotes: 0
Reputation: 289
Without your own constants and magic numbers:
TimeSpan.FromMilliseconds(x).TotalSeconds
Upvotes: 28
Reputation: 5767
How about 1s = 1000ms
http://www.google.com/search?q=milliseconds+to+seconds&btnG=Google+Search&aq=0&oq=milliseconds+
Upvotes: 3