C# + Format TimeSpan

后端 未结 10 697
忘掉有多难
忘掉有多难 2020-12-09 01:44

I am trying to format a TimeSpan element in the format of \"[minutes]:[seconds]\". In this format, 2 minutes and 8 seconds would look like \"02:08\". I have tried a variety

10条回答
  •  猫巷女王i
    2020-12-09 01:48

    Try this:

    DateTime startTime = DateTime.Now;
    // Do Stuff
    TimeSpan duration = DateTime.Now.Subtract(startTime);
    
    Console.WriteLine("[paragraph of information] Total Duration: " + duration.Minutes.ToString("00") + ":" + duration.Seconds.ToString("00"));
    

提交回复
热议问题