如何转换当前时间在Visual Studio毫秒? [英] How to Convert the Current Time to milliseconds in Visual Studio?
问题描述
我想当前时间(系统时间)转换成毫秒...是否有任何内置的功能,我可以用它来轻松解决这个问题。
I am trying to convert the current time (system time) in to milliseconds ...is there any inbuilt functions i can use to solve this easily .
例如我用下面的代码来获取时间并显示。
For example i have used the following code to get the time and display it.
System.Diagnostics.Debug.WriteLine("Time "+ String.Format("{0:mm:ss.fff}",DateTime.Now));
输出我得到的是
36时间:50.527
Time 36:50.527
在分:seconds.milliseconds
as in minutes:seconds.milliseconds
我要我现在在为毫秒哪有时间进行转换。
I need to convert the time i got now in to Milliseconds.
推荐答案
您需要一个时间跨度
表示自您的划时代的时间。在我们的例子,这是0天为了得到这个,只是减去0天( DateTime.Min
)从 DateTime.Now $ C $ 。C>
You need a TimeSpan
representing the time since your epoch. In our case, this is day 0. To get this, just subtract day 0 (DateTime.Min
) from DateTime.Now
.
var ms = (DateTime.Now - DateTime.MinValue).TotalMilliseconds;
System.Diagnostics.Debug.WriteLine("Milliseconds since the alleged birth of christ: " + ms);
这篇关于如何转换当前时间在Visual Studio毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!