C# 如何将刻度转换为分钟?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/386341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 01:28:46  来源:igfitidea点击:

How do I convert ticks to minutes?

c#datetimetimespan

提问by

I have a ticks value of 28000000000 which should be 480 minutes but how can I be sure? How do I convert a ticks value to minutes?

我的刻度值为 28000000000,应该是 480 分钟,但我怎么确定?如何将刻度值转换为分钟?

回答by Blounty

there are 600 million ticks per minute. ticksperminute

每分钟有 6 亿次滴答。 每分钟滴答声

回答by thinkbeforecoding

You can do this way :

你可以这样做:

TimeSpan duration = new TimeSpan(tickCount)
double minutes = duration.TotalMinutes;

回答by Patrik H?gne

TimeSpan.FromTicks(28000000000).TotalMinutes;

回答by Patrick Desjardins

A single tick represents one hundred nanoseconds or one ten-millionth of a second. FROM MSDN.

一个刻度代表一百纳秒或百万分之一秒。来自 MSDN。

So 28 000 000 000 * 1/10 000 000 = 2 800 sec. 2 800 sec /60 = 46.6666min

所以 28 000 000 000 * 1/10 000 000 = 2 800 秒。2 800 秒 /60 = 46.6666 分钟

Or you can do it programmaticly with TimeSpan:

或者您可以使用 TimeSpan 以编程方式执行此操作:

    static void Main()
    {
        TimeSpan ts = TimeSpan.FromTicks(28000000000);
        double minutesFromTs = ts.TotalMinutes;
        Console.WriteLine(minutesFromTs);
        Console.Read();
    }

Both give me 46 min and not 480 min...

两者都给我 46 分钟而不是 480 分钟...

回答by Jon Skeet

The clearest way in my view is to use TimeSpan.FromTicksand then convert that to minutes:

在我看来,最清晰的方法是使用TimeSpan.FromTicks,然后将其转换为分钟:

TimeSpan ts = TimeSpan.FromTicks(ticks);
double minutes = ts.TotalMinutes;

回答by Mike Scott

TimeSpan.FromTicks( 28000000000 ).TotalMinutes;

TimeSpan.FromTicks( 28000000000 ).TotalMinutes;

回答by zaheer ahmad

DateTime mydate = new Date(2012,3,2,5,2,0);
int minute = mydate/600000000;

will return minutes of from given date (mydate) to current time.hope this help.cheers

将返回从给定日期 (mydate) 到当前时间的分钟数。希望这有帮助。干杯