每秒获取Tick并转换为String值?

编程入门 行业动态 更新时间:2024-10-22 15:36:20
本文介绍了每秒获取Tick并转换为String值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何获取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值?

本文发布于:2023-11-01 18:22:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550067.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   Tick   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!