how to convert seconds in min:sec format
A versatile version is to use TimeSpan
like this:
var span = new TimeSpan(0, 0, seconds); //Or TimeSpan.FromSeconds(seconds); (see Jakob C´s answer)
var yourStr = string.Format("{0}:{1:00}",
(int)span.TotalMinutes,
span.Seconds);
int totalSeconds = 222;
int seconds = totalSeconds % 60;
int minutes = totalSeconds / 60;
string time = minutes + ":" + seconds;
Just for completeness I will add an answer using TimeSpan
(works as of .NET 4.0):
int seconds = 1045;
var timespan = TimeSpan.FromSeconds(seconds);
Console.WriteLine(timespan.ToString(@"mm\:ss"));