Velocity Reviews > How to convert Seconds to X Hours Y Minutes Z Seconds?

# How to convert Seconds to X Hours Y Minutes Z Seconds?

00_CP_D12
Guest
Posts: n/a

 04-05-2005

Is there an easy way in ASP.NET to convert seconds to Hours: Minutes:
Seconds?

For example, 65 seconds will return 0 hr, 1 min, 5 secs.

Thanks...

Juan T. Llibre
Guest
Posts: n/a

 04-05-2005
Use the TimeSpan object.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaņol
Ven, y hablemos de ASP.NET...
======================

"00_CP_D12" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Is there an easy way in ASP.NET to convert seconds to Hours: Minutes:
> Seconds?
>
> For example, 65 seconds will return 0 hr, 1 min, 5 secs.
>
> Thanks...
>
>

Kevin Spencer
Guest
Posts: n/a

 04-05-2005
Hours = Seconds / 3600
Minutes = Seconds / 60

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"00_CP_D12" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Is there an easy way in ASP.NET to convert seconds to Hours: Minutes:
> Seconds?
>
> For example, 65 seconds will return 0 hr, 1 min, 5 secs.
>
> Thanks...
>
>

dilipv
Junior Member
Join Date: Feb 2008
Posts: 1

 02-22-2008
hi ther,
just try out the following given solution it might help you out.

Int64 seconds = 19800;
TimeSpan span = new TimeSpan(TimeSpan.TicksPerSecond * seconds);
string str = span.Hours.ToString("00") + ":" + span.Minutes.ToString("00") + ":" + span.Seconds.ToString("00");
Response.Write(str)

Thank you
Jitesh
Programmer
.Net Consulting