How show minutes and seconds with Stopwatch()

前端 未结 7 482
北荒
北荒 2021-02-01 12:20

I need to show also the minutes, actually I use this code for show the seconds, but also need the minutes

TimeSpan ts = stopwatch.Elapsed;
Console.WriteLine(\"F         


        
7条回答
  •  臣服心动
    2021-02-01 13:11

    I've coded this way:

    using System.Diagnostics;
    ...
    
    Stopwatch watch = new Stopwatch();
    watch.Start();
    
    // here the complex program.
    ...
    
    watch.Stop();
    
    TimeSpan timeSpan = watch.Elapsed;
    
    Console.WriteLine("Time: {0}h {1}m {2}s {3}ms", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds);
    

提交回复
热议问题