469,610 Members | 2,118 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Convert seconds to 00:00:00 (HH:MM:SS) format. Please help

I have this for example:

Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.

Thanks in advance!
Dec 27 '05 #1
14 3763

Perhaps

Dim iSeconds As Int32 = 3600
Dim ts As New TimeSpan(0, 0, iSeconds)
MsgBox(ts.ToString)

/JB

On Tue, 27 Dec 2005 18:57:01 +0800, "Michael Barrido"
<jm***@hotmail.com> wrote:
I have this for example:

Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.

Thanks in advance!


Dec 27 '05 #2

TimeSpan span = TimeSpan.FromSeconds(3600);
string timeInterval = interval.ToString("HH:MM:SS");

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Michael Barrido" <jm***@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP11.phx.gbl...
I have this for example:

Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.

Thanks in advance!

Dec 27 '05 #3
Thank you very much!
"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:en**************@tk2msftngp13.phx.gbl...

TimeSpan span = TimeSpan.FromSeconds(3600);
string timeInterval = interval.ToString("HH:MM:SS");

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Michael Barrido" <jm***@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP11.phx.gbl...
I have this for example:

Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.

Thanks in advance!


Dec 27 '05 #4
Thank you very much!
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAM> wrote in message
news:4c********************************@4ax.com...

Perhaps

Dim iSeconds As Int32 = 3600
Dim ts As New TimeSpan(0, 0, iSeconds)
MsgBox(ts.ToString)

/JB

On Tue, 27 Dec 2005 18:57:01 +0800, "Michael Barrido"
<jm***@hotmail.com> wrote:
I have this for example:

Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.

Thanks in advance!

Dec 27 '05 #5
On Tue, 27 Dec 2005 13:16:46 +0200, "Vadym Stetsyak" <va*****@ukr.net>
wrote:

TimeSpan span = TimeSpan.FromSeconds(3600);
string timeInterval = interval.ToString("HH:MM:SS");


That won't work. The ToString method of the TimeSpan
object does not take a format parameter, so it would
still be

Dim span As TimeSpan = TimeSpan.FromSeconds(iSeconds)
MsgBox(span.ToString())

But you are right: .FromSeconds is a more appropriate answer to
the original problem (though it looks as if FromSeconds requires
quite a bit more work to be performed under the covers). Ah, I'm
just nit-picking.

Have a look at the ToString function below (from Reflector).
A shorter, faster version could be written by hand to deal with
the specific requirement, but the formatting is the same as what
the original poster wanted:

---snip---
Public Overrides Function ToString() As String
Dim builder1 As New StringBuilder
Dim num1 As Integer = CType((Me._ticks / 864000000000), Integer)
Dim num2 As Long = (Me._ticks Mod 864000000000)
If (Me._ticks < 0) Then
builder1.Append("-")
num1 = -num1
num2 = -num2
End If
If (num1 <> 0) Then
builder1.Append(num1)
builder1.Append(".")
End If
builder1.Append(Me.IntToString(CType(((num2 / 36000000000) Mod
CType(24, Long)), Integer), 2))
builder1.Append(":")
builder1.Append(Me.IntToString(CType(((num2 / CType(600000000,
Long)) Mod CType(60, Long)), Integer), 2))
builder1.Append(":")
builder1.Append(Me.IntToString(CType(((num2 / CType(10000000,
Long)) Mod CType(60, Long)), Integer), 2))
Dim num3 As Integer = CType((num2 Mod CType(10000000, Long)),
Integer)
If (num3 <> 0) Then
builder1.Append(".")
builder1.Append(Me.IntToString(num3, 7))
End If
Return builder1.ToString
End Function
---snip---

/JB


Dec 27 '05 #6
"Michael Barrido" <jm***@hotmail.com> schrieb:
Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.


\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Dec 27 '05 #7

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message news:eJ**************@TK2MSFTNGP10.phx.gbl...
"Michael Barrido" <jm***@hotmail.com> schrieb:
Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.


\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


For a bit more detail ( AM/PM) do this:

\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss tt"))
///

I had been trying to get the same results as the original poster and also wanted AM/PM
and remembered a post by Chris Dunaway not too long ago helping me with the same
problem. So, I thought I would add the "tt" to help.
james

Dec 27 '05 #8
On Tue, 27 Dec 2005 07:22:28 -0600, "james" <jjames700ReMoVeMe at
earthlink dot net> wrote:

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message news:eJ**************@TK2MSFTNGP10.phx.gbl...
"Michael Barrido" <jm***@hotmail.com> schrieb:
Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.


\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


For a bit more detail ( AM/PM) do this:

\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss tt"))
///

I had been trying to get the same results as the original poster and also wanted AM/PM
and remembered a post by Chris Dunaway not too long ago helping me with the same
problem. So, I thought I would add the "tt" to help.
james


No, that is not quite enough:

The "tt"-specifier depends on the current culture. On my
machine (English XP, but with default Danish regional settings),
there are no AM/PM symbols, so the suggested "hh:mm:ss tt"
would not provide complete time information on my system.
I would just see something like "11:59:00 " (yes, including the
trailing space).

At the very least, make sure that the requirements for using
"hh:mm:ss tt" are fulfilled, i.e. that AM/PM designators have
been specified for the current culture.

For completeness sake:

hh = 12-hour format (1-12).

HH = 24-hour format (0-23).

Be careful not to write MM (month) instead of mm (minute).

For more information, see "Custom DateTime Format Strings"
in the documentation.

Regards,

Joergen Bech



Dec 27 '05 #9
"james" <jjames700ReMoVeMe at earthlink dot net> schrieb:
Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.


\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss"))
///


For a bit more detail ( AM/PM) do this:

\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss tt"))
///


Well, I would not do that if I would want to display the size (quantity) of
a time span.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 27 '05 #10
James,

As it says AM/PM is only where the English language is used.

And simply enough use other languages 24hours clocks.

Although the way we say it by instance in Dutch is almost the same as in
English.

20:00 is acht uur s'avonds (eight O'Clock in the evening)

:-)

Cor
Dec 27 '05 #11

"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAM> wrote in message news:li********************************@4ax.com...
On Tue, 27 Dec 2005 07:22:28 -0600, "james" <jjames700ReMoVeMe at
earthlink dot net> wrote:

For a bit more detail ( AM/PM) do this:

\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss tt"))
///

I had been trying to get the same results as the original poster and also wanted AM/PM
and remembered a post by Chris Dunaway not too long ago helping me with the same
problem. So, I thought I would add the "tt" to help.
james


No, that is not quite enough:

The "tt"-specifier depends on the current culture. On my
machine (English XP, but with default Danish regional settings),
there are no AM/PM symbols, so the suggested "hh:mm:ss tt"
would not provide complete time information on my system.
I would just see something like "11:59:00 " (yes, including the
trailing space).

At the very least, make sure that the requirements for using
"hh:mm:ss tt" are fulfilled, i.e. that AM/PM designators have
been specified for the current culture.

For completeness sake:

hh = 12-hour format (1-12).

HH = 24-hour format (0-23).

Be careful not to write MM (month) instead of mm (minute).

For more information, see "Custom DateTime Format Strings"
in the documentation.

Regards,

Joergen Bech


Thank you Joergen. I have read up on the "Custom DateTime Format Strings", since Chris had given me
the help that I mentioned in my post.
Next time I'll leave my 2 cents in my pocket.
james
Dec 27 '05 #12

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message news:O7**************@TK2MSFTNGP11.phx.gbl...
"james" <jjames700ReMoVeMe at earthlink dot net> schrieb:
Dim iSeconds as int32 = 3600 '3600 seconds is one hour
How do i convert it to "01:00:00" ? Please help.

\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss"))
///


For a bit more detail ( AM/PM) do this:

\\\
MsgBox((New Date).AddSeconds(3600).ToString("hh:mm:ss tt"))
///


Well, I would not do that if I would want to display the size (quantity) of a time span.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Herfried, sorry about that. I didn't realize that the original poster was wanting to display
a passage of time. My intent was not to cause a problem.
I have been working on an old DOS based , database system conversion and the original
database engine stored the time of day in seconds. I had posted a question here some time
back on how to convert those seconds back to a readable time format including AM/PM
and Chris had helped me with that. For some reason, I thought the original poster had
been looking for a similar solution. I guess that is what happens when I have not had my
full 3 cups of coffee before reading and responding to posts!!!
james

Dec 27 '05 #13

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl...
James,

As it says AM/PM is only where the English language is used.

And simply enough use other languages 24hours clocks.

Although the way we say it by instance in Dutch is almost the same as in English.

20:00 is acht uur s'avonds (eight O'Clock in the evening)

:-)

Cor

Cor, of course you are correct. I should have not answered the original post without
having a better understanding of what the original poster was trying to achieve. And
what his requirements were.
I'll try not to respond to posts unless I have had my full quota of coffee from now on. :-)
james
Dec 27 '05 #14
Herfried, sorry about that. I didn't realize that the original poster was wanting to display
a passage of time. My intent was not to cause a problem.
I have been working on an old DOS based , database system conversion and the original
database engine stored the time of day in seconds. I had posted a question here some time
back on how to convert those seconds back to a readable time format including AM/PM
and Chris had helped me with that. For some reason, I thought the original poster had
been looking for a similar solution. I guess that is what happens when I have not had my
full 3 cups of coffee before reading and responding to posts!!!
james


's okay. The discussion took another direction because
the Date object and its ToString formatting options was suggested.

My replies (and yours) were to the specifics of those posts - not
to the problem of the original poster. I knew that we had gotten
off the track. No harm in that. As long as it is clear that those
replies are not specific to the problem outlined in the original post.

I sometimes throw something out there which might only be 80%
correct (e.g. something that works, turns out to be more easily done
another way). No harm in that *provided* someone else steps in
and offers the 100% solution.

When I had my Hex->Integer problem, I was happy to be informed
that Integer.Parse could handle it correctly. But even happier when
Armin suggested "System.Convert.ToInt32(hexvalue, 16)" which
was exactly what I needed.

Sometimes the Devil is in the details, but if the first replies to
any questions had to be 100% perfect, we might as well close
the group now. If, however, we help each other out, we'll eventually
get there.

/JB

Dec 27 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by bonnie.tangyn | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.