Elapsed

CSharp · Console

/Program.cs

using System;
using System.Diagnostics;
using System.Threading;

					
public class Program
{
	public static void Main()
	{
		Stopwatch timer = Stopwatch.StartNew();
        Thread.Sleep(1234);
        timer.Stop();
        TimeSpan timeSpan = timer.Elapsed;
        Console.WriteLine("Total processing time... {0:00}:{1:00}:{2:00}.{3}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds);
		// OUTPUT   Total processing time... 00:00:01.243
		
        DateTime start = DateTime.Now;
		Console.WriteLine("Process starting at: " + start.ToString("dd/MM/yyyy hh:mm:ss tt"));
		Thread.Sleep(1234);
		DateTime end = DateTime.Now;
		Console.WriteLine("Process finished at: " + end.ToString("dd/MM/yyyy hh:mm:ss tt"));
		TimeSpan diff = (end  - start);
		Console.WriteLine("Total elapsed time:  {0:00}:{1:00}:{2:00}.{3}", diff.Hours, diff.Minutes, diff.Seconds, diff.Milliseconds);
		// OUTPUT
		// Process starting at: 29/11/2018 12:12:57 AM
		// Process finished at: 29/11/2018 12:12:59 AM
		// Total elapsed time:  00:00:01.234
    }
}
;