Android Question Converting integer values to ticks long value

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

If I have 3 separate integer values representing a time such like:

Dim intHours As Int = 10
Dim intMinutes As Int = 30
Dim IntSeconds As Int = 0

for the actual time of 10:30:00, can you tell me how to convert those 3 integers into a ticks long value so I can pass it to StartServiceAtExact ?

I tried to search in the community but did not seem to find how to do it.

Thanks.
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
if I understood correctly...


B4X:
Dim intHours As Int = 10
Dim intMinutes As Int = 30
Dim IntSeconds As Int = 0
     
DateTime.TimeFormat="HH:mm:ss"
 
Dim strHours As String = intHours
If strHours.Length=1 Then strHours="0" & strHours
 
Dim strMinutes As String = intMinutes
If strMinutes.Length=1 Then strMinutes="0" & strMinutes
 
Dim strtSeconds As String = IntSeconds
If strtSeconds.Length=1 Then strtSeconds="0" & strtSeconds
 
Dim strTime As String=strHours & ":" & strMinutes & ":" & strtSeconds
 
Dim longTime As Long=DateTime.TimeParse(strTime)
 
Log(longTime)

'or to schedule the start of service
Log(DateTime.Now + DateTime.TicksPerHour * intHours + DateTime.TicksPerMinute * intMinutes + DateTime.TicksPerSecond*IntSeconds)

the above code can be simplified
 
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
if I understood correctly...


B4X:
Dim intHours As Int = 10
Dim intMinutes As Int = 30
Dim IntSeconds As Int = 0
    
DateTime.TimeFormat="HH:mm:ss"
 
Dim strHours As String = intHours
If strHours.Length=1 Then strHours="0" & strHours
 
Dim strMinutes As String = intMinutes
If strMinutes.Length=1 Then strMinutes="0" & strMinutes
 
Dim strtSeconds As String = IntSeconds
If strtSeconds.Length=1 Then strtSeconds="0" & strtSeconds
 
Dim strTime As String=strHours & ":" & strMinutes & ":" & strtSeconds
 
Dim longTime As Long=DateTime.TimeParse(strTime)
 
Log(longTime)

'or to schedule the start of service
Log(DateTime.Now + DateTime.TicksPerHour * intHours + DateTime.TicksPerMinute * intMinutes + DateTime.TicksPerSecond*IntSeconds)

the above code can be simplified
Hi,

Thanks for the coding. That will help.
 
Upvote 0
Top