Tips & Trucos: Convertir Segundos a Minutos, Horas y Días – VB y C#
Publicado: 19/10/2009 | Autor: alexjimenez |
| Tweet
| Tweet
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..!!
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 |
|
|
|
|
Deja tu Comentario




![Validate my RSS feed [Valid RSS]](http://validator.w3.org/feed/images/valid-rss-rogers.png)
