472,353 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time...
6
by: Kalle Anke | last post by:
I want to parse a date string, for example '2005-09-23', and since I haven't done this before I would like to ask what is the best way to do it. ...
3
by: nriesch | last post by:
In the documentation, the "Second" property of class DateTime is a value between 0 and 59. In UTC time, approximately every year of so, a leap...
2
by: Andy | last post by:
Hi guys, I'm writing a program with a feature of accepting user input as command text and parsing it to correct function calls...example: "5...
1
by: Karch | last post by:
I am doing some experimenting with serialization (for use with Service Broker) and I am having a problem converting from a .NET DateTime (in the...
7
by: TheLostLeaf | last post by:
DateTime tTime = DateTime.Now; ------------------------------------------------------------------------------------------- tTime returns...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see...
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to...
6
by: i_robot73 | last post by:
I have a file, containing hex values for dates (MMDDYYYY)<status code><??such as: ...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.