I need format TimeSpan to minutes and seconds(without hours), I looks to MSDN formatting but not found any example which I can reuse.
Example of what I need:
TimeSpan.FromSeconds(1) --> 00:01
TimeSpan.FromSeconds(60) --> 01:00
TimeSpan.FromSeconds(3600) --> 60:00
TimeSpan.FromSeconds(36000) --> 600:00
Any ideas which format possible use to convert TimeSpan to string in minutes:seconds format?
Try this:
var timeSpan = TimeSpan.FromSeconds(3123);
var result = string.Format("{0:D2}:{1:D2}", (int) timeSpan.TotalMinutes, timeSpan.Seconds);
// result = "52:03"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With