我有一些代码可以测量某些操作花费的时间。如果夏令时在操作过程中生效,我会得到不准确的数据。
比如我在做
DateTime startAt = DateTime.Now;
DoOperation(); //day light saving takes effect in the middle
int seconds = (DateTime.Now - startAt).TotalSeconds;
//second has wrong seconds
有没有办法衡量这一点?
谢谢
最佳答案
改用 StopWatch
类...例如
var stopWatch = new StopWatch();
stopWatch.Start();
//code here
stopWatch.Stop()
Console.WriteLine("elapsed millisconds " + stopwatch.ElapsedMilliseconds);
关于.net - 测量耗时会计日光节约,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6618239/