如何使用C#跟踪微秒时间 [英] How to track the time in Microseconds using C#

查看:379
本文介绍了如何使用C#跟踪微秒时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了1000行的代码。

我需要知道每个块导致的时间。

所以我使用了字符串生成器来存储当前时间。



 StringBuilder sb =  new  StringBuilder(); 







 sb.Append(DateTime.Now.ToString()); 





我使用上面的代码来节点导致时间的所有区域。

然后我写了要分析的文本文档。



这没有显示出太大的差异。



我需要显示以微秒为单位的时间。



有没有办法以微秒显示当前时间



 8/7/2014  5  15  13  100  PM 



 8/7 / 2014  5 : 15  13  330  PM 



 8/7/2014  5  15  13  434  PM 





我以微秒为单位得到时间我可以正确分析代码。



如何解决这个。

解决方案

 StringBuilder sb =  new  StringBuilder(); 
sb.Append( String .Format( {0:MM / dd / yyyy HH:mm:ss.FFF},DateTime.Now));





此链接可以提供帮助:自定义日期和时间格式字符串


c#编码非常简单。你只需要编写下面的代码。你想要以毫秒为单位显示时间..



 DateTime.Now.ToString(  dd / MM / yyyy hh:mm:ss:FFFFFFF tt); 





例如,

我在我的标签上显示。

 lblDate.Text = DateTime.Now.ToString(  dd / MM / yyyy hh:mm:ss:FFFFFFF tt ); 


I have written a code for 1000 lines.
I need to know how much time each block is causing.
So I used a string builder to store current Time.

StringBuilder sb=new StringBuilder();




sb.Append(DateTime.Now.ToString());



I am using the above code to node all the region which causes time.
Then I've written that to a Text document to Analyse.

That's not showing much differences.

I need to display time in microseconds.

Is there any way to display current time in Microseconds

8/7/2014 5:15:13 :100 PM


8/7/2014 5:15:13 :330 PM


8/7/2014 5:15:13 :434 PM



I f I get the timing in Microseconds I can analyse the code properly.

How to solve this.

解决方案

StringBuilder sb=new StringBuilder();
sb.Append(String.Format("{0:MM/dd/yyyy HH:mm:ss.FFF}", DateTime.Now));



This link can help : Custom Date and Time Format Strings


It is very simple thing in c# coding. You just have to write below code.Where you want to display time in miliseconds..

DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss :FFFFFFF tt");



For Example,
I have display that on my label.

lblDate.Text =DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss :FFFFFFF tt");


这篇关于如何使用C#跟踪微秒时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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