在微秒C#时间 [英] C# time in microseconds

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

问题描述

我正在寻找如何格式化时间,包括微秒。
我使用类日期时间,它allowes(使用属性)来获取数据到毫秒为单位,这是不enougth。
我试着使用蜱,但我不知道如何将其转化为微秒。

I am searching how to format time including microseconds. I'm using class DateTime, it allowes (using properties) to get data till miliseconds, which is not enougth. I tried using Ticks, but I didn't know how to translate it to microseconds.

推荐答案

您可以使用FFFFFF在格式字符串重新present微秒:

You can use "ffffff" in a format string to represent microseconds:

Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.ffffff"));

要转换一些蜱微秒,只需使用:

To convert a number of ticks to microseconds, just use:

long microseconds = ticks / (TimeSpan.TicksPerMillisecond / 1000);

如果这些不帮你,请提供你想要做什么的更多信息。

If these don't help you, please provide more information about exactly what you're trying to do.

编辑:我原来乘以 1000,以避免分裂 TimeSpan.TicksPerMillisecond 1000。然而,当失去精度,事实证明,在 TicksPerMillisecond 实际上是10,000一个恒定值 - 这样你就可以通过1000没有问题划分,事实上,我们可以只使用:

I originally multiplied ticks by 1000 to avoid losing accuracy when dividing TimeSpan.TicksPerMillisecond by 1000. However, It turns out that the TicksPerMillisecond is actually a constant value of 10,000 - so you can divide by 1000 with no problem, and in fact we could just use:

const long TicksPerMicrosecond = 10;

...

long microseconds = ticks / TicksPerMicrosecond;

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

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