如何从Stopwatch.GetTimestamp()到DateTime? [英] How do i get from Stopwatch.GetTimestamp() to a DateTime?
问题描述
重复的:如何获取tick的时间戳精度在.NET / C#?
我如何从Stopwatch.GetTimestamp()获取到一个DateTime
Duplicate of: How to get timestamp of tick precision in .NET / C#?
How do i get from Stopwatch.GetTimestamp() to a DateTime
假设Stopwatch.IsHighResolution是真的
Assume Stopwatch.IsHighResolution is true
推荐答案
如果它是一个高分辨率计数器,不能保证该值与实时有任何关联 - 例如,它可能是从计算机启动时刻录。对于非 - 高分辨率计时器,您可以使用新的DateTime(Stopwatch.GetTimestamp())
,但这不一定会给出有用的值用于高分辨率定时器。 (这当然不在我的盒子上。)
If it's a high resolution counter, there's no guarantee that the value has any correlation with the real time - for example, it may well be "ticks since the computer booted." For a non-high resolution timer, you could use new DateTime(Stopwatch.GetTimestamp())
but that won't necessarily give a useful value for a high resolution timer. (It certainly doesn't on my box.)
你想用什么? Stopwatch
的想法是测量时间的间隔。
What are you trying to use this for? The idea of Stopwatch
is to measure intervals of time.
这篇关于如何从Stopwatch.GetTimestamp()到DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!