Sigueme en Twitter
AJDev.net en Facebook
AJDev.net en Facebook
Traducir
Mapa de Visitas
Locations of visitors to this page

Hola a Todos,

Aquí les dejo unos simples truquillos de convertir Segundos a Minutos, Horas y Días. Utilizando TimeSpan.

Nota: el Response.Write es por que utilice una pagina ASP.net y en el Load cargaba el resultado :)

En Visual Basic:

   1: Dim segundos As Double = 7950 'Los Segundos a Probar
   2:  
   3: 'Prueba 1: Total Dias, Total de Horas, Total Minutos, Total Segundos
   4: Dim t As New TimeSpan
   5:  
   6: Response.Write("Prueba 1: Dias: " + t.FromSeconds(segundos).TotalDays.ToString() +
   7:  " Tiempo: " + t.FromSeconds(segundos).TotalHours.ToString() + ":" + t.FromSeconds(segundos).TotalMinutes.ToString() + ":" + t.FromSeconds(segundos).TotalSeconds.ToString())
   8:  
   9: 'Prueba 2: Dias, Hora, Minutos y Segundos
  10: Dim t2 As TimeSpan = TimeSpan.FromSeconds(segundos)
  11: Response.Write("<br> Prueba 2: Dias: " + t2.Days.ToString() + " Tiempo: " + t2.Hours.ToString() + ":" + t2.Minutes.ToString() + ":" + t2.Seconds.ToString())

 

En C#:

   1: double segundos=7950 ; //Los Segundos a probar
   2: TimeSpan t =new TimeSpan;
   3: //Prueba 1: Total Dias, Total de Horas, Total Minutos, Total Segundos
   4: Response.Write("Prueba 1: Dias: " + t.FromSeconds
   5: (segundos).TotalDays.ToString() + " Tiempo: " + t.FromSeconds
   6: (segundos).TotalHours.ToString() + ":" + t.FromSeconds
   7: (segundos).TotalMinutes.ToString() + ":" + t.FromSeconds
   8: (segundos).TotalSeconds.ToString());
   9:  
  10: TimeSpan t2= TimeSpan.FromSeconds(segundos);
  11: //Prueba 2: Dias, Hora, Minutos y Segundos
  12: Response.Write("<br> Prueba 2: Dias: " + t2.Days.ToString() + " Tiempo: " +
  13: t2.Hours.ToString() + ":" + t2.Minutes.ToString() + ":" +
  14: t2.Seconds.ToString());

Espero que le sea de Ayuda..!!



Tags: Articulos -


Te ha gustado este Post?


Pues seria genial si pudieras compartirlo con otras personas y asi llegarle a mas personas que pudiera ser util esta publicación. Animate a compartir

Compartir Compartir este Post Compartir este Post Compartir este Post Compartir este Post

Nombres:
Correo:
Página:
Comentario: