Seconds as hh:mm:ss

  • Thread starter Thread starter Able
  • Start date Start date
A

Able

Dear friends

I need to format seconds as hh:mm:ss. I see a lot of coding transforming
seconds to hh:mm:ss. Somebody know a short way?

Regards Able
 
Try the following:

-----------------
Dim objTime As New TimeSpan(0, 0, 1234)
Debug.WriteLine(objTime.Hours & ":" & objTime.Minutes & ":" &
objTime.Seconds)
-----------------

There's probably better and shorter ways to do this, but I can't think of
any at the minute.

Note, you'll need to handle cases where the duration goes over one day
(86400 seconds)

HTH,

Trev.
 
Thanks Trev

Able

Trev Hunter said:
Try the following:

-----------------
Dim objTime As New TimeSpan(0, 0, 1234)
Debug.WriteLine(objTime.Hours & ":" & objTime.Minutes & ":" &
objTime.Seconds)
-----------------

There's probably better and shorter ways to do this, but I can't think of
any at the minute.

Note, you'll need to handle cases where the duration goes over one day
(86400 seconds)

HTH,

Trev.
 
* "Able said:
I need to format seconds as hh:mm:ss. I see a lot of coding transforming
seconds to hh:mm:ss. Somebody know a short way?

\\\
Dim ts As TimeSpan = TimeSpan.FromSeconds(23423423)
MsgBox(ts.Hours.ToString() & ":" & ts.Minutes.ToString() & ":" & ts.Seconds.ToString())
///
 
I believe you get the same answer if you initialize your timespan to 9023
which indicates that the answer for 23423423 isn't correct.

At least one would notice the extra hours with:
MsgBox(((ts.Days * 24) + ts.Hours).ToString & ":" &
ts.Minutes.ToString() & ":" & ts.Seconds.ToString())
 
or...

Dim secs As Long = 123456
Dim dt As New DateTime(secs * 10000D)
MsgBox(dt.ToString("HH:mm:ss"))



dominique
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top