How can I get from Stopwatch.GetTimestamp () to DateTime?

Duplicate: How do I get a tick accuracy mark in .NET / C #?
How can I get from Stopwatch.GetTimestamp () to DateTime

Assume Stopwatch.IsHighResolution is true

+5
source share
2 answers

If this is a high-resolution counter, there is no guarantee that the value has any relation to real time - for example, it may be "ticking from the moment the computer boots up." For a timer with a low resolution, you can use new DateTime(Stopwatch.GetTimestamp()), but this will not necessarily give a useful value for a timer with a high resolution. (This, of course, is not on my box.)

? Stopwatch .

+6

, , :

Stopwatch sw = Stopwatch.StartNew();
//do stuff
sw.Elapsed; //or
sw.ElapsedMilliseconds;

. DateTime, DateTimes , .

( ) :

startTime = Stopwatch.GetTimestamp();

totalTime = (Stopwatch.GetTimestamp() - startTime) / 10000; 
//it was assumed 10,000 ticks was a millisecond, incorrectly
0