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;
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;
Divide by 1000 or use
czasAlg.Elapsed.TotalSeconds
Without your own constants and magic numbers:
TimeSpan.FromMilliseconds(x).TotalSeconds
.Seconds
gets the seconds place of the TimeSpan. So if it was 1 minute and 30 seconds you would get 30
back where .TotalSeconds
would return 90
. –
Salita TimeSpan.FromMilliseconds(x).Duration().TotalSeconds
–
Mclaren Just to be different:
Multiply by 0.001.
double.Parse(string.Format("{0}e-3", czasAlg.ElapsedMilliseconds))
–
Lachrymal 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
© 2022 - 2025 — McMap. All rights reserved.