每秒获取Tick并转换为String值? [英] Get Ticks per second and convert to String value?
问题描述
如何获取DateTime.UtcNow的每秒钟数,并将其转换为String值?
How do I get number of ticks per second of DateTime.UtcNow and convert it to a String value?
BAD QUESTION:再试一次获得百万分之一秒
BAD QUESTION: try again Get ten millionths of a second
推荐答案
DateTime
的特定值没有与之相关联的每秒滴答他们所在的 DateTime
中的刻度是蜱虫。蜱是100纳秒长,因此每秒有10,000,000个。
A particular value of DateTime
doesn't have a "ticks per second" associated with it; ticks are ticks no matter which DateTime
they're in. Ticks are 100 nanoseconds long, so there are 10,000,000 of them per second.
现在得到一个字符串就像字符串文字10000000一样简单...虽然通常你会获得一个数字,只需调用 ToString()
上例如,您可以使用:
Now to get that as a string is as simple as the string literal "10000000"... although in general you would obtain a number and just call ToString()
on it. For instance, you could use:
string ticksPerSecond = TimeSpan.TicksPerSecond.ToString();
您的问题是一个稍微奇怪的问题,所以我想知道我们是否缺少某些东西...可以您可以更详细地编辑问题,了解您正在尝试的内容。例如,您是否尝试确定特定 DateTime
中特定第二个中的刻度数?这最容易做到:
Your question is a slightly odd one, so I wonder whether we're missing something... could you edit the question with more details about what you're trying to do. For example, are you trying to determine the number of ticks within the particular second of a particular DateTime
? That's most easily done as:
long ticks = dt.Ticks % TimeSpan.TicksPerSecond;
这篇关于每秒获取Tick并转换为String值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!