Convert seconds to minutes+seconds?

Sorry for the elementary question, but I am new to C & C#.

I need to convert seconds (upt to 3600 seconds) to minutes & seconds. For example I need to convert 90 seconds to 1 minute and 30 seconds. I'm struggling with how to get and manipulate the remainder after I divide 90 by 60.

Your patience is appreciated...;)


Answer this question

Convert seconds to minutes+seconds?

  • Hydra20010

    There is another way to deal with time, you have in .net an object called TimeSpan, that have some nice methods (see the documentation).

    Here is an example for getting the time from secconds:


    TimeSpan t = TimeSpan.FromSeconds(90);

    Console.WriteLine(t.Hours);

    Console.WriteLine(t.Minutes);

    Console.WriteLine(t.Seconds);

    Console.WriteLine(t.ToString());



     


    That code gives this output to the console:
    0
    1
    30
    00:01:30

  • sbogollu

    Duh.... Thanks!
  • Bryan Chriscoli

    bistok,

    Excellent! Thanks.


  • parsec

    minutes = total / 60;

    seconds = total % 60;



  • JonathanCox

    Gotta love google. Thanks!

  • Convert seconds to minutes+seconds?