Android Question Time Writing

Oke

Member
Licensed User
Longtime User
How to write code for time, for example 10:00 to 12:00, but the time really matches the system time ?
active time will start at 10:00 and end after exceeding 12:00
 

AnandGupta

Expert
Licensed User
Longtime User
How to write code for time, for example 10:00 to 12:00, but the time really matches the system time ?
active time will start at 10:00 and end after exceeding 12:00
Start a timer. Check time every minute, say. When time 10 show time. When time 12 stop.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
How to write code for time, for example 10:00 to 12:00, but the time really matches the system time ?
active time will start at 10:00 and end after exceeding 12:00
i believe you want it to start in the background right?
if so you can use a service and start it at a specific time like 10:00 and do what you want to do.

it is hard to understand what you want to archive from your short post.
what should happen between 10:00 to 12:00?
 
Upvote 0

Oke

Member
Licensed User
Longtime User
i believe you want it to start in the background right?
if so you can use a service and start it at a specific time like 10:00 and do what you want to do.

it is hard to understand what you want to archive from your short post.
what should happen between 10:00 to 12:00?
B4X:
DateTime.TimeFormat = "hh:mm"
Label1.Text = DateTime.Time(DateTime.Now)
If Label1 > 10:00 And Label1 < 12:00 then
   log(aktive)
End if
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
B4X:
DateTime.TimeFormat = "hh:mm"
Label1.Text = DateTime.Time(DateTime.Now)
If Label1 > 10:00 And Label1 < 12:00 then
   log(aktive)
End if

this will not work. you need to convert text to long and check if something is bigger or not like this:


B4X:
    DateTime.TimeFormat = "HH:mm"
    
    Dim lbl1 As Label
    lbl1.Initialize("")
    lbl1.Text = DateTime.Time(DateTime.Now)
 
    Dim startTime As String = "10:00"
    Dim endTime As String = "12:00"
    
    If DateTime.TimeParse(lbl1.Text) > DateTime.TimeParse(startTime) And DateTime.TimeParse(lbl1.Text) <  DateTime.TimeParse(endTime) Then
        Log($"Yes, you are between ${startTime } and ${endTime}"$)
    Else
        Log($"NO, you are not between ${startTime } and ${endTime}"$)
    End If

NO, you are not between 10:00 and 12:00
 
Upvote 0

Oke

Member
Licensed User
Longtime User
this will not work. you need to convert text to long and check if something is bigger or not like this:


B4X:
    DateTime.TimeFormat = "HH:mm"
   
    Dim lbl1 As Label
    lbl1.Initialize("")
    lbl1.Text = DateTime.Time(DateTime.Now)
 
    Dim startTime As String = "10:00"
    Dim endTime As String = "12:00"
   
    If DateTime.TimeParse(lbl1.Text) > DateTime.TimeParse(startTime) And DateTime.TimeParse(lbl1.Text) <  DateTime.TimeParse(endTime) Then
        Log($"Yes, you are between ${startTime } and ${endTime}"$)
    Else
        Log($"NO, you are not between ${startTime } and ${endTime}"$)
    End If

Thank you sir....
 
Upvote 0
Top