Forum Discussion

simranjit's avatar
simranjit
Binge Watcher
7 years ago

ToISOString() return wrong date time

Hi,

Working on time based application, when reset the device and launch our application instant, we are getting wrong date and time instead of current date and time.
date = CreateObject("roDateTime")
print date.ToISOString()


Output is "2019-01-09T02:59Z" instead of "2019-02-12T10:42Z", showing approximate 34 days previous static date every time.
But if we restart the device and launch the application after internet connection, then we are getting correct date and time.

Please suggest the solution for this problem.

Thanks in advance,
Simran 

5 Replies

  • renojim's avatar
    renojim
    Community Streaming Expert
    There is no solution. The box doesn't have a battery backed-up RTC. I doesn't know the correct date/time until it establishes an Internet connection and contacts an NTP server. If your app can't operate without the correct time, you either have to wait for Internet connection to be established or exit if the connection hasn't been established. You can't rely on roDateTime unless the box is able to contact the Roku NTP server.

    -JT
  • destruk's avatar
    destruk
    Streaming Star
    Perhaps you can check for the date/time, and if it is the default date you receive when there isn't an internet connection available, simply not use the data and check it again later in the application.
    Although why your device would require the internet but not be able to access the date/time server, sounds like a critical flaw in your internet routing service/gateway/proxy maybe?
  • "renojim" wrote:
    There is no solution.  The box doesn't have a battery backed-up RTC.  I doesn't know the correct date/time until it establishes an Internet connection and contacts an NTP server.  If your app can't operate without the correct time, you either have to wait for Internet connection to be established or exit if the connection hasn't been established.  You can't rely on roDateTime unless the box is able to contact the Roku NTP server.

    -JT

    Thanks 
  • "destruk" wrote:
    Perhaps you can check for the date/time, and if it is the default date you receive when there isn't an internet connection available, simply not use the data and check it again later in the application.
    Although why your device would require the internet but not be able to access the date/time server, sounds like a critical flaw in your internet routing service/gateway/proxy maybe?

    Thanks, we will look into internet routing service.
  • destruk's avatar
    destruk
    Streaming Star
    If your content list json or xml is generated in realtime on the server via a script, you could have the server provide the time in that file when it is sent to the Roku (as a time from epoch in seconds), or simply run a php script on the server to return the data separately, and then you could start a timer service on the Roku and add both together to get the time without using the Roku time server.  Just another 'solution'.