sec2hms in pb
Posted: Thu Jun 15, 2006 11:07 am
Code updated For 5.20+
i needed a procedure to transform seconds in h
s with padding 0 optional (example without padding 1:2:3 with padding 01:02:03)
if anyone has something better please feal free to post it here or make mine better or corect bugs if any
maybe someone else needs something like this so i here it is
i needed a procedure to transform seconds in h
if anyone has something better please feal free to post it here or make mine better or corect bugs if any
maybe someone else needs something like this so i here it is
Code: Select all
Procedure.s sec2hms(sec$,padding=1)
hours=Int(Val(sec$)/3600)
minutes = Int(Val(sec$) / 60) % 60
seconds = Int(Val(sec$)) % 60
If padding
If hours < 10
hours$="0"+Str(hours)
ElseIf hours = 0
hours$="00"
Else
hours$=Str(hours)
EndIf
If minutes < 10
minutes$ = "0" + Str(minutes)
ElseIf minutes = 0
minutes$ = "00"
Else
minutes$ = Str(minutes)
EndIf
If seconds < 10
seconds$ = "0" + Str(seconds)
ElseIf seconds = 0
seconds$ = "00"
Else
seconds$ = Str(seconds)
EndIf
Else
hours$=Str(hours)
minutes$ = Str(minutes)
seconds$ = Str(seconds)
EndIf
hms$=hours$+":"+minutes$+":"+seconds$
ProcedureReturn hms$
EndProcedure