469,271 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Parsing Seconds Into DateTime Representation

good day,

I simply would like to know as to how I can parse seconds to convert them
into equivalent DateTime representation. To be more persice,
I have a DirectShow app written in VB.NET, with a timer in it. Timer ticks
every 1000 milliseconds and then I get the current position of the video
in seconds (the return type here is integer). However seconds in this case
can be greater than 60 in fact all the way up to the maximum amount of
digits Integer type would allow. So what I would like to do is to get
current position, parse it and output it in Hours : Minutes : Seconds
format.

any help would be greatly appreciated.

Nov 21 '05 #1
5 10154
Try setting a TimeSpan variable type :
dim ts as TimeSpan = new TimeSpan(...)
dim Days as integer = ts.Days
dim Hours as integer = ts.Hours
.....

"Nikeman" wrote:
good day,

I simply would like to know as to how I can parse seconds to convert them
into equivalent DateTime representation. To be more persice,
I have a DirectShow app written in VB.NET, with a timer in it. Timer ticks
every 1000 milliseconds and then I get the current position of the video
in seconds (the return type here is integer). However seconds in this case
can be greater than 60 in fact all the way up to the maximum amount of
digits Integer type would allow. So what I would like to do is to get
current position, parse it and output it in Hours : Minutes : Seconds
format.

any help would be greatly appreciated.


Nov 21 '05 #2
Nikeman,

Do you mean
dt as datetime
dt = dt.addseconds(myseconds * 1000)

http://msdn.microsoft.com/library/de...condstopic.asp

Be aware that in the datetime the ticks are (as in MSDN always written) in
100-nanoseconds. From which value I never understood what it is meant by
that.

I hope this helps

Cor
Nov 21 '05 #3
doh
dt as datetime
dt = dt.addseconds(myticks \ 1000)
Nov 21 '05 #4
hello everyone.
I tried what you have suggested, and your solution works well.

Thanks very much for your response.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:#2**************@TK2MSFTNGP09.phx.gbl...
Nikeman,

Do you mean
dt as datetime
dt = dt.addseconds(myseconds * 1000)

http://msdn.microsoft.com/library/de...condstopic.asp
Be aware that in the datetime the ticks are (as in MSDN always written) in
100-nanoseconds. From which value I never understood what it is meant by
that.

I hope this helps

Cor

Nov 21 '05 #5
Nikeman,
I find the "easiest" way is to use TimeSpan.FromSeconds method.

Dim seconds As Integer = 75
Dim elapsed As TimeSpan = TimeSpan.FromSeconds(seconds)
Dim s As String = elapsed.ToString()

TimeSpan also has FromDays, FromHours, FromMilliseconds, FromMinutes, and
FromTicks which are useful for other "durations". The cool thing about the
TimeSpan.From methods is that they accept Doubles so you can have:

Dim elapsed As TimeSpan = TimeSpan.FromSeconds(1.5)

To create an duration of 1.5 seconds...

Note I will convert the TimeSpan to a DateTime if I need custom Formatting:

Dim seconds As Integer = 75
Dim elapsed As TimeSpan = TimeSpan.FromSeconds(seconds)
Dim value As DateTime = DateTime.MinValue.Add(elapsed)
Dim s As String = value.ToString("mm:ss")

Hope this helps
Jay

"Nikeman" <1@1.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
good day,

I simply would like to know as to how I can parse seconds to convert them
into equivalent DateTime representation. To be more persice,
I have a DirectShow app written in VB.NET, with a timer in it. Timer ticks
every 1000 milliseconds and then I get the current position of the video
in seconds (the return type here is integer). However seconds in this case
can be greater than 60 in fact all the way up to the maximum amount of
digits Integer type would allow. So what I would like to do is to get
current position, parse it and output it in Hours : Minutes : Seconds
format.

any help would be greatly appreciated.


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Gerrit Holl | last post: by
6 posts views Thread by Kalle Anke | last post: by
3 posts views Thread by nriesch | last post: by
7 posts views Thread by TheLostLeaf | last post: by
7 posts views Thread by Daniel Fetchinson | last post: by
3 posts views Thread by =?Utf-8?B?U2hlbGRvbg==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.