如何转换当前时间在Visual Studio毫秒? [英] How to Convert the Current Time to milliseconds in Visual Studio?

查看:805
本文介绍了如何转换当前时间在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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆