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

Discussion in 'ASP .Net' started by 00_CP_D12, Apr 5, 2005.

1. ### 00_CP_D12Guest

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...

00_CP_D12, Apr 5, 2005

2. ### Juan T. LlibreGuest

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" <> wrote in message
news:...
>
> 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, Apr 5, 2005

3. ### Kevin SpencerGuest

Hours = Seconds / 3600
Minutes = Seconds / 60

--
HTH,

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

"00_CP_D12" <> wrote in message
news:...
>
> 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, Apr 5, 2005
4. ### dilipv

Joined:
Feb 13, 2008
Messages:
1
0
Converting hours to minutes

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)