Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created May 21, 2016 01:37
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/a75703c45040eb6eb7cc6b090a28644b to your computer and use it in GitHub Desktop.
Save Fhernd/a75703c45040eb6eb7cc6b090a28644b to your computer and use it in GitHub Desktop.
Aritmética con la estructura TimeSpan.
using System;
namespace Articulo.Cap06
{
public class AritmeticaTimeSpan
{
public static void Main()
{
// Crea un objeto TimeSpan restando 1 segundo al intervalo
// de tiempo de 10 días:
TimeSpan casiDiezDias = TimeSpan.FromDays(10) - TimeSpan.FromSeconds(1);
// Uso de propiedades de TimeSpan para mostrar los valores
// de tiempo para el intervalo resultado de la sustracción anterior:
Console.WriteLine (casiDiezDias.Days); // 9
Console.WriteLine (casiDiezDias.Hours); // 23
Console.WriteLine (casiDiezDias.Minutes); // 59
Console.WriteLine (casiDiezDias.Seconds); // 59
Console.WriteLine (casiDiezDias.Milliseconds); // 0
// Total de tiempo en el intervalo resultante:
Console.WriteLine (casiDiezDias.TotalDays); // 9.99998842592593
Console.WriteLine (casiDiezDias.TotalHours); // 239.999722222222
Console.WriteLine (casiDiezDias.TotalMinutes); // 14399.9833333333
Console.WriteLine (casiDiezDias.TotalSeconds); // 863999
Console.WriteLine (casiDiezDias.TotalMilliseconds); // 863999000
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment