How do I convert ticks to minutes?

C#DatetimeTimespan

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

TimeSpan.FromTicks(28000000000).TotalMinutes;

Solution 2 - C#

>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...

Solution 3 - C#

You can do this way :

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

Solution 4 - C#

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;

Solution 5 - C#

there are 600 million ticks per minute. ticksperminute

Solution 6 - C#

TimeSpan.FromTicks( 28000000000 ).TotalMinutes;

Solution 7 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen HView Question on Stackoverflow
Solution 1 - C#Patrik HägneView Answer on Stackoverflow
Solution 2 - C#Patrick DesjardinsView Answer on Stackoverflow
Solution 3 - C#thinkbeforecodingView Answer on Stackoverflow
Solution 4 - C#Jon SkeetView Answer on Stackoverflow
Solution 5 - C#BlountyView Answer on Stackoverflow
Solution 6 - C#Mike ScottView Answer on Stackoverflow
Solution 7 - C#zaheer ahmadView Answer on Stackoverflow