Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 22, 2015 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/08b67b8c3c26c08c1a81 to your computer and use it in GitHub Desktop.
Save Fhernd/08b67b8c3c26c08c1a81 to your computer and use it in GitHub Desktop.
Uso de la clase Stopwatch en C#.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.Diagnostics;
using System.Threading;
namespace Receta.CSharp.R0303
{
public class UsoStopwatch
{
public static void Main()
{
Console.WriteLine(Environment.NewLine);
Stopwatch sw = new Stopwatch();
// Inicia el cronómetro:
sw.Start();
// Simula la ejecución durante 10':
Thread.Sleep(10000);
// Detiene el cronómetro:
sw.Stop();
// Obtiene el tiempo transcurrido:
TimeSpan ts = sw.Elapsed;
// Formato de la representación del tiempo
// transcurrido:
string formatoTiempo = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine("Tiempo cronometrizado: {0}", formatoTiempo);
Console.WriteLine(Environment.NewLine);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment