|
-
Oct 26th, 2004, 02:15 AM
#1
Thread Starter
Frenzied Member
Formatting time, (not that easy)
Hi there VB Geniuses,
I have a problem here which has been bugging me for a while.
I have a list of time here but they are listed in seconds of the day.
1.359375
300.2813
600.2422
901.3594
1200.117
1500.219
They are roughly at every 5mins intervals, how do i convert them into hh:mm:ss ?
I can do it in excel but i am puzzled how to do it in vb 
I will watch out for my timely answer.
Thanks !!!!
Last edited by dinosaur_uk; Oct 27th, 2004 at 09:19 AM.
-
Oct 26th, 2004, 02:56 AM
#2
VB Code:
Public Function GetTimeElapsed(ByVal intTimeStamp As Long) As DateTime
If intTimeStamp > 86400 OrElse intTimeStamp < 1 Then
Return DateTime.Parse("00:00:00")
Else
Dim intSeconds As Int32
Dim intHH As Int32, intMM As Int32, intSS As Int32
intSeconds = Decimal.ToInt32(intTimeStamp)
If intSeconds > 60 Then
intSS = (intSeconds Mod 60)
intMM = (intSeconds \ 60)
If intMM > 60 Then
intHH = intMM \ 60
intMM = intMM Mod 60
End If
End If
Dim dtTime As DateTime
dtTime = DateTime.Parse(intHH.ToString & ":" & intMM & ":" & intSS)
Return dtTime
End If
End Function
To use it:
MessageBox.Show(GetTimeElapsed(13122.383).ToLongTimeString)
-
Oct 26th, 2004, 03:01 AM
#3
Thread Starter
Frenzied Member
Oh my god ?
Dear Mr Mendhak,
How did you know that ? All Hail the VB Saint...
The dinosaur is impressed.
-
Oct 26th, 2004, 03:09 AM
#4
Thread Starter
Frenzied Member
Oh no !!
I have tried the code, and it seems to work up till it reaches 00:55:00 then it does not work ????
it crashes
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: String was not recognized as a valid DateTime.
And it highlights
dtTime = DateTime.Parse(intHH.ToString & ":" & intMM & ":" & intSS)
-
Oct 26th, 2004, 03:32 AM
#5
My mistake, try this:
dtTime = DateTime.Parse(intHH.ToString & ":" & intMM.ToString & ":" & intSS.ToString)
-
Oct 26th, 2004, 03:34 AM
#6
I tried with the erroneous code, still works fine. What input did you give?
-
Oct 26th, 2004, 03:40 AM
#7
Hows this, I tried to make the code a bit smaller but I figured it would be enough as it is. 
VB Code:
Public Function SecondsToDateTime(ByVal seconds As Double) As DateTime
Return New DateTime(seconds * TimeSpan.TicksPerSecond)
End Function
:accurate:
I don't live here any more.
-
Oct 26th, 2004, 03:43 AM
#8
Wooh.
We have a new VB Angel.
-
Oct 26th, 2004, 03:45 AM
#9
Originally posted by mendhak
Wooh.
We have a new VB Angel.
dont worry your would be a saint.
-
Oct 26th, 2004, 06:17 AM
#10
Thread Starter
Frenzied Member
Amazing, the VB Angels having a cup of tea in VB Heaven, good stuff, i am impressed guys....
I have learnt so much, (from someone who hates programming) and i am even finding it *more enjoyable... 
<catches some wild boar for VB Angels....>
-
Oct 26th, 2004, 07:15 AM
#11
I'll settle for VB Demon.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|