|
-
Apr 25th, 2005, 09:41 AM
#1
Thread Starter
Frenzied Member
How to get Mins and Seconds from seconds left.
Hi there,
How do i convert a number which is in seconds (eg 310 seconds) to 5 minutes 10 seconds?
Do i use the mod function (which i cant seem to be able to use in the pocket pc development.,.)
Last edited by dinosaur_uk; Apr 27th, 2005 at 02:44 AM.
-
Apr 25th, 2005, 10:08 AM
#2
Fanatic Member
Re: How to get Mins and Seconds from seconds left.
here is one i used before:
VB Code:
Public Function formatLength(ByVal howManySeconds As Object) As Object
Dim mySeconds As Object
Dim myHours As Object
Dim myMinutes As Object
On Error GoTo errCheck '//just incase of an error
' //duration '
mySeconds = howManySeconds
'if mySeconds is greater or equal to 3,600 seconds
If mySeconds >= 3600 Then
'get hours which is equal to seconds divided by 3600
myHours = mySeconds / 3600
'set the seconds to the numbers after the decimal sign
'thats what mod does
mySeconds = mySeconds Mod 3600
Else
'if not greater than 3600, just set it to 0
myHours = 0
End If
If mySeconds >= 60 Then
'greater than or equal to 60
'set the minutes equal to the value of (seconds divided by 60).
'and get the remaining numbers after the decimal
'which will be the seconds
'using the mod sign
myMinutes = mySeconds \ 60
mySeconds = mySeconds Mod 60
Else
'if not set to 0
myMinutes = 0
End If
'return
formatLength = Format$(myHours, "00:") & Format$(myMinutes, "00:") & Format$(mySeconds, "00")
Exit Function
errCheck:
formatLength = ""
End Function
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Apr 26th, 2005, 11:09 AM
#3
Addicted Member
Re: How to get Mins and Seconds from seconds left.
If you can't use Mod function in PPC development environ, wouldn't the following work:
VB Code:
Public Function ConvertRawSeconds(RawSeconds As Int) As String
Dim RemainingSecs As Integer
Dim Minutes As Integer
Dim Seconds As Integer
RemainingSecs = RawSeconds
Minutes = 0
Seconds = 0
Do While RemainingSecs > 0
If RemainingSecs > 59 Then
Minutes = Minutes + 1
RemainingSecs = RemainingSecs - 60
Else
Seconds = RemainingSecs
RemainingSecs = 0
End If
Loop
' And borrowing/adapting syntax from Strider's previous posting
ConvertRawSeconds = Format$(Minutes, "00:") & Format$(Seconds, "00")
End Function
Obviously you could add one more If/Then switch to account for hours if needed.
-
Apr 27th, 2005, 02:43 AM
#4
Thread Starter
Frenzied Member
Re: How to get Mins and Seconds from seconds left.
Found it !!
 Originally Posted by wossname
VB Code:
Dim ts As TimeSpan = TimeSpan.FromSeconds(3931) '3931 seconds
MessageBox.Show("Hours: " & ts.Hours)
MessageBox.Show("Minutes: " & ts.Minutes)
MessageBox.Show("Seconds: " & ts.Seconds)
-
Apr 27th, 2005, 04:27 PM
#5
Addicted Member
Re: How to get Mins and Seconds from seconds left.
That was certainly more elegant than my suggestion.
-
Apr 28th, 2005, 03:30 AM
#6
Thread Starter
Frenzied Member
Re: How to get Mins and Seconds from seconds left.
Heee...i know....
Thank goodness i checked the forums again...
It was wossname who posted it.. i am just putting it here so pple knows it works on the CF.
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
|