Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the method to record and calculate time?

I want to create a method that takes two variables timeIn and timeOut and compare the times between the two to draw a difference.

How can I make it so that that timeIn is recorded at time now, and timeOut would also be a time for the present date? It is as if I checked into a parking lot, and then check out sort thing.

Could I take timeOut and subtract it from timeIn to get the difference?

I am using c# code.

like image 810
GivenPie Avatar asked Dec 17 '22 02:12

GivenPie


1 Answers

try this :

    System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

       doLogWork() ...

    sw.Stop();

Console.Write(       sw.Elapsed.TotalSeconds + " Sec    / " +
                    ((float)sw.Elapsed.TotalSeconds / (float)60).ToString("N2") + 
                    " min" );

edit

DONT USE TIMESPAN

ticks represented in Stopwatch are based on a combination of the hardware of the machine and the operating system. Contrast this to TimeSpan where Ticks are defined as 100 nanosecond intervals -- which is obviously machine/OS independent.

like image 125
Royi Namir Avatar answered Dec 22 '22 00:12

Royi Namir