Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Calculating time difference in minutes [duplicate]

I have got the following code:

DateTime start = DateTime.Now;
Thread.Sleep(60000);
DateTime end = DateTime.Now;

and I would like to calculate the difference in minutes between start and end. How am I supposed to do it? For the example above, the result should be '1'.

Thanks in advance!

like image 248
P Sawicki Avatar asked Jul 18 '17 13:07

P Sawicki


1 Answers

I think a more elegant way of doing it would be by using the Stopwatch-Class

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
like image 56
Xzibitee Avatar answered Oct 04 '22 01:10

Xzibitee