使用C#获取时间(以毫秒为单位) [英] Get time in milliseconds using C#
问题描述
我正在编写一个程序,其中需要以毫秒为单位。到时间,我的意思是一个永远不会等于自己的数字,并且总是比第二秒大1000个数字。我尝试将 DateTime.Now
转换为 TimeSpan
并获得 TotalMilliseconds
从那开始...但是我听说它并不十分准确。
I'm making a program in which I need to get the time in milliseconds. By time, I mean a number that is never equal to itself, and is always 1000 numbers bigger than it was a second ago. I've tried converting DateTime.Now
to a TimeSpan
and getting the TotalMilliseconds
from that... but I've heard it isn't perfectly accurate.
有没有更简单的方法?
推荐答案
使用 秒表
类。
提供一组可用于精确测量经过时间的方法和
属性。
Provides a set of methods and properties that you can use to accurately measure elapsed time.
在这里实现它的好信息:
There is some good info on implementing it here:
性能测试:使用System.Diagnostics.Stopwatch进行精确的运行时测量
这篇关于使用C#获取时间(以毫秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!