How do I convert ticks to minutes?
Asked Answered
M

7

106

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?

Maddy answered 22/12, 2008 at 14:17 Comment(0)
C
158
TimeSpan.FromTicks(28000000000).TotalMinutes;
Castanon answered 22/12, 2008 at 14:22 Comment(0)
S
129

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

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

Or you can do it programmaticly with 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...

Sunless answered 22/12, 2008 at 14:22 Comment(4)
lol who down voted me? Both mathematical and coded one really give me 46 min and not this 480 min.Sunless
Maybe someone down voted you for rounding 46.6666 to 46? ;-) No, actually, I had down voted you by mistake, I have removed the down vote now. Sorry!Ricoriki
Actually, to be clear, I have not only removed the down vote. I have up voted your comprehensive answer. Sir.Ricoriki
Voted up for including the math version as well as the TimeSpan version.Martainn
D
35

You can do this way:

TimeSpan duration = new TimeSpan(tickCount)
double minutes = duration.TotalMinutes;
Dearing answered 22/12, 2008 at 14:21 Comment(1)
lol - you answered one minute earlier than Jon Skeet, but his answer has more votes!?Mcavoy
S
26

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

TimeSpan ts = TimeSpan.FromTicks(ticks);
double minutes = ts.TotalMinutes;
Sequestration answered 22/12, 2008 at 14:22 Comment(0)
P
11

there are 600 million ticks per minute. ticksperminute

Pennyroyal answered 22/12, 2008 at 14:20 Comment(1)
ticks / TimeSpan.TicksPerMinuteChristenachristendom
P
4

TimeSpan.FromTicks( 28000000000 ).TotalMinutes;

Panicle answered 22/12, 2008 at 14:25 Comment(0)
E
1
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

Evelinaeveline answered 2/4, 2013 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.