获取每秒刻度数并转换为字符串值?
如何获取 DateTime.UtcNow 每秒的刻度数并将其转换为字符串值?
糟糕的问题:再试一次获取百万分之十秒
How do I get number of ticks per second of DateTime.UtcNow and convert it to a String value?
BAD QUESTION: try again Get ten millionths of a second
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
DateTime
的特定值没有与之关联的“每秒滴答数”;无论处于哪个DateTime
中,刻度都是刻度。刻度的长度为 100 纳秒,因此每秒有 10,000,000 个刻度。现在将其作为字符串获取就像字符串文字“10000000”一样简单......尽管通常您会获得一个数字并只需对其调用
ToString()
即可。例如,您可以使用:您的问题有点奇怪,所以我想知道我们是否遗漏了某些内容...您可以编辑问题,并提供有关您想要做什么的更多详细信息吗?例如,您是否试图确定特定
DateTime
的特定秒内的刻度数?最容易做到的是:A particular value of
DateTime
doesn't have a "ticks per second" associated with it; ticks are ticks no matter whichDateTime
they're in. Ticks are 100 nanoseconds long, so there are 10,000,000 of them per second.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: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:我认为您可能需要
TimeSpan.TicksPerSecond
。I think you may want
TimeSpan.TicksPerSecond
.您发现每秒的滴答声在 TimeSpan 上是一个常量:
但不确定您要做什么......
You find the ticks per second as a constant on TimeSpan:
Not sure what you are trying to do though...
DateTime 值中每秒的刻度数始终为 10000000。一个刻度为 100 纳秒。
因此,如果您想将其转换为字符串:
The number of ticks per second in a DateTime value is always 10000000. One tick is 100 nanoseconds.
So, if you want to convert that to a string: