469,601 Members | 2,105 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,601 developers. It's quick & easy.

Seconds as hh:mm:ss

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
Nov 20 '05 #1
6 2702
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" <ab**@epost.no> wrote in message
news:NM******************@news2.e.nsc.no...
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

Nov 20 '05 #2
Thanks Trev

Able

"Trev Hunter" <hu*********@hotmail.com> skrev i melding
news:uP**************@TK2MSFTNGP10.phx.gbl...
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" <ab**@epost.no> wrote in message
news:NM******************@news2.e.nsc.no...
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


Nov 20 '05 #3
* "Able" <ab**@epost.no> scripsit:
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())
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
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())
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
* "Able" <ab**@epost.no> scripsit:
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()) ///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #5
or...

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

dominique
"Able" <ab**@epost.no> wrote in message
news:NM******************@news2.e.nsc.no...
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

Nov 20 '05 #6
little correction

*10000000D and not *10000D

dominique

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
or...

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

dominique
"Able" <ab**@epost.no> wrote in message
news:NM******************@news2.e.nsc.no...
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


Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by hikums | last post: by
15 posts views Thread by Jay Tee | last post: by
1 post views Thread by Vishal Bhargava | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.