473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 4047

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Ho | last post by:
I have a small application which is running every x minutes and I need to display remaining time on the screen in this format (example): "Next start will be in: 00:13:25" , and it should...
10
by: Kiran | last post by:
Hi, I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to date. I get the following error Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not...
14
by: Michael Barrido | last post by:
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!
1
by: Jason Chan | last post by:
DateTime mydate = new DateTime(2006,1,1,0,0,0); string testStr = mydate.ToString("hh:mm:ss"); //return 12:00:00 mydate = new DateTime(2006,1,1,1,0,0) testStr = mydate.ToString("hh:mm:ss");...
6
by: google0 | last post by:
I know this is a trivial function, and I've now spent more time searching for a surely-already-reinvented wheel than it would take to reinvent it again, but just in case... is there a published,...
10
by: bonnie.tangyn | last post by:
Dear all In my ASP page, user can enter date in dd/mm/yyyy format. How can I use Javascript to convert dd/mm/yyyy to yyyy-mm-dd hh:mm:ss. Please give me some advices. Cheers Bon
3
by: vunet.us | last post by:
What is the best method to convert milliseconds (after midnight January 1, 1970 GMT) to formatted time example: 972798180000 ==10/18/2000 14:08:11
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.