Alhootti Active Member Feb 9, 2024 #1 Hi guys I'm using timer each 1000 ms will display time to label. The issue is that after one month, the time is delayed by 2 minutes. How do you get rid of this issue? Note: I'm using an anderiod TV box integrated with battery 3 volts to save time.
Hi guys I'm using timer each 1000 ms will display time to label. The issue is that after one month, the time is delayed by 2 minutes. How do you get rid of this issue? Note: I'm using an anderiod TV box integrated with battery 3 volts to save time.
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2024 #2 Don't sum the seconds yourself. Check the system time (DateTime.Now) every timer tick. Upvote 0
Alhootti Active Member Feb 11, 2024 #3 I'm using this code could you please edit it. B4X: Sub Process_Globals Dim Timer1 As Timer End Sub Sub Activity_Create(FirstTime As Boolean) Timer1.Initialize("tmr",1000) Timer1.Enabled = True End Sub Sub tmr_tick DateTime.TimeFormat = "hh:mm:ss" Label1.Text = DateTime.Time(DateTime.Now) End Sub Upvote 0
I'm using this code could you please edit it. B4X: Sub Process_Globals Dim Timer1 As Timer End Sub Sub Activity_Create(FirstTime As Boolean) Timer1.Initialize("tmr",1000) Timer1.Enabled = True End Sub Sub tmr_tick DateTime.TimeFormat = "hh:mm:ss" Label1.Text = DateTime.Time(DateTime.Now) End Sub
B Brian Dean Well-Known Member Licensed User Longtime User Feb 11, 2024 #4 B4X: Label1.Text = DateTime.Time(DateTime.Now) This is the correct code - you are reading the Android device time which should be UTC time maintained by an internet connection. If it shows an incorrect time it means that your Android TV box is incorrect. Where is your box getting its UTC reference from? Upvote 0
B4X: Label1.Text = DateTime.Time(DateTime.Now) This is the correct code - you are reading the Android device time which should be UTC time maintained by an internet connection. If it shows an incorrect time it means that your Android TV box is incorrect. Where is your box getting its UTC reference from?
ilan Expert Licensed User Longtime User Feb 11, 2024 #5 Alhootti said: I'm using this code could you please edit it. B4X: Sub Process_Globals Dim Timer1 As Timer End Sub Sub Activity_Create(FirstTime As Boolean) Timer1.Initialize("tmr",1000) Timer1.Enabled = True End Sub Sub tmr_tick DateTime.TimeFormat = "hh:mm:ss" Label1.Text = DateTime.Time(DateTime.Now) End Sub Click to expand... B4X: DateTime.TimeFormat = "HH:mm:ss" change hh to HH Upvote 0
Alhootti said: I'm using this code could you please edit it. B4X: Sub Process_Globals Dim Timer1 As Timer End Sub Sub Activity_Create(FirstTime As Boolean) Timer1.Initialize("tmr",1000) Timer1.Enabled = True End Sub Sub tmr_tick DateTime.TimeFormat = "hh:mm:ss" Label1.Text = DateTime.Time(DateTime.Now) End Sub Click to expand... B4X: DateTime.TimeFormat = "HH:mm:ss" change hh to HH
Alhootti Active Member Feb 11, 2024 #6 Brian Dean said: B4X: Label1.Text = DateTime.Time(DateTime.Now) This is the correct code - you are reading the Android device time which should be UTC time maintained by an internet connection. If it shows an incorrect time it means that your Android TV box is incorrect. Where is your box getting its UTC reference from? Click to expand... The problem is there is no Internet connection somewhere. Upvote 0
Brian Dean said: B4X: Label1.Text = DateTime.Time(DateTime.Now) This is the correct code - you are reading the Android device time which should be UTC time maintained by an internet connection. If it shows an incorrect time it means that your Android TV box is incorrect. Where is your box getting its UTC reference from? Click to expand... The problem is there is no Internet connection somewhere.
Alhootti Active Member Feb 11, 2024 #7 ilan said: View attachment 150726 B4X: DateTime.TimeFormat = "HH:mm:ss" change hh to HH Click to expand... In our country the official format is 12 am/pm system Upvote 0
ilan said: View attachment 150726 B4X: DateTime.TimeFormat = "HH:mm:ss" change hh to HH Click to expand... In our country the official format is 12 am/pm system
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2024 #8 Based on the description in the first post, your Android TV loses precision over time. If there is no internet connection then there isn't anything that you can do to fix it. With an internet connection you can get the time from a NTP server. Upvote 0
Based on the description in the first post, your Android TV loses precision over time. If there is no internet connection then there isn't anything that you can do to fix it. With an internet connection you can get the time from a NTP server.
Alhootti Active Member Feb 11, 2024 #9 Erel said: Based on the description in the first post, your Android TV loses precision over time. Click to expand... I also utilise four timers. Do they affect the precision of time? the RAM is 4GB Last edited: Feb 11, 2024 Upvote 0
Erel said: Based on the description in the first post, your Android TV loses precision over time. Click to expand... I also utilise four timers. Do they affect the precision of time? the RAM is 4GB
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2024 #10 No. As long as you are getting the time using DateTime.Now then your app will not affect the clock precision. It is possible that your app is leaking a resource and after a month it runs very slow. Does the clock show the correct time after you restart the app? Overall, mobile devices are not really built to run apps forever. It is a good practice to kill the app after 24 hours and restart it. You can do it with a second "watchdog" app. Upvote 0
No. As long as you are getting the time using DateTime.Now then your app will not affect the clock precision. It is possible that your app is leaking a resource and after a month it runs very slow. Does the clock show the correct time after you restart the app? Overall, mobile devices are not really built to run apps forever. It is a good practice to kill the app after 24 hours and restart it. You can do it with a second "watchdog" app.
Alhootti Active Member Feb 11, 2024 #11 Thank you Erel Good idea. Is there method to refresh the time every one hour programmatically to get ride this issue? Upvote 0
Thank you Erel Good idea. Is there method to refresh the time every one hour programmatically to get ride this issue?
B Brian Dean Well-Known Member Licensed User Longtime User Feb 12, 2024 #12 Is there method to refresh the time every one hour programmatically to get ride this issue? Click to expand... Well, you know that your device loses two minutes after one month, which is around two seconds every twelve hours. So in your timer tick events you could have a correction factor and increase it by two seconds every twelve hours (or one second every six hours) and add it to the reported DateTime(Now) value. It would not "get rid of the issue" because your device probably does not lose exactly two minutes every thirty days, but it would be a useful step forward. Last edited: Feb 12, 2024 Upvote 0
Is there method to refresh the time every one hour programmatically to get ride this issue? Click to expand... Well, you know that your device loses two minutes after one month, which is around two seconds every twelve hours. So in your timer tick events you could have a correction factor and increase it by two seconds every twelve hours (or one second every six hours) and add it to the reported DateTime(Now) value. It would not "get rid of the issue" because your device probably does not lose exactly two minutes every thirty days, but it would be a useful step forward.