Android Question Seekbar seconds in HH:MM:SS

Fusseldieb

Active Member
Licensed User
Longtime User
Hi there,
I have a Seekbar in my app that goes from 0 to 7200 (2 hours).
Now I want to display a label that appears that selected value in HH:MM:SS
I have tried many examples and read the entire forum about it and it doesn't work.
The only thing I could make work are the seconds, which I used "Value Mod 60".
But how about Minutes and Hours?

Any help would be appreciated :)
 

mangojack

Well-Known Member
Licensed User
Longtime User
try this ..
B4X:
Dim sVal, hrs, mins As Int    
sVal = seekbar1.Valu
hrs = Floor(sVal / 60)
mins = sVal Mod 60
    
If hrs = 1 Then
  Log (hrs & " hr  :  " & mins & "  mins")
Else
  Log (hrs & " hrs  :  " & mins & "  mins")
End If
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Or this:

B4X:
    For i = 0 To 7200 Step 60
    Log(DateTime.Time(i*1000))
Next
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try This:
B4X:
DateTime.SetTimeZone(0)
    For i = 0 To 7200 Step 60
        Log(DateTime.Time(i*1000))
    Next
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Being in the UK I tend to forget about such issues, until reminded.
 
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
Try This:
B4X:
DateTime.SetTimeZone(0)
    For i = 0 To 7200 Step 60
        Log(DateTime.Time(i*1000))
    Next
Thanks, but that doesn't display the seconds and it wont work with the Seekbar :c

I have now modified the code from @mangojack and now I stuck on how I archieve the hours to display:

B4X:
Dim sVal, minutes, seconds,hours As Int   
sVal = Value
hours = ???
minutes = Floor(sVal / 60)
seconds = sVal Mod 60
   
  Log (hours ":" & (minutes Mod 60) & ":" & seconds)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It will display the seconds if you feed it from the seek bar, the Step 60 in the code just sends each minute. Which is why it isn't displaying seconds. I just didn't want to log 7200 entries. You can do:

B4X:
DateTime.SetTimeZone(0)
    For i = 0 To 7200
        Log(DateTime.Time(i*1000))
    Next

If you wish.
 
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
It will display the seconds if you feed it from the seek bar, the Step 60 in the code just sends each minute. Which is why it isn't displaying seconds. I just didn't want to log 7200 entries. You can do:

B4X:
DateTime.SetTimeZone(0)
    For i = 0 To 7200
        Log(DateTime.Time(i*1000))
    Next

If you wish.
Woww! That simple :D
Thanks so much ^^

I used in the Seekbar this now:

B4X:
Sub Seek1_ValueChanged (Value As Int, UserChanged As Boolean)
DateTime.SetTimeZone(0)
Log(DateTime.Time(Value*1000))
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You only need to set the time zone once, probably in Activity_Create, unless you are using the clock for anything else like displaying time then you can record the initial setting with DateTime.TimeZoneOffset, and set it back when you need to
 
Upvote 0
Top