How to get phone's time offset in seconds (and milliseconds)?

158 views
Skip to first unread message

Robb Holmes

unread,
Jul 6, 2015, 7:32:33 PM7/6/15
to tas...@googlegroups.com
I'm new to Tasker, have little experience with javascript and none with Java. Any pointers for further reading will be welcome; I don't expect anyone to lay out step-by-step directions. And I'm prepared for the possibility that what I want to do may not be possible. Someone asked nearly the same question about three years ago, and there was no answer then.

How can I determine the cell phone's time offset from UTC? By UTC, I mean a standard of accuracy, not the GMT time zone. I want the same data I would get if I could use an NTP client to determine local time offset. I'm not trying to set the phone's time; I just want to know the offset. This needs to work on unrooted phones.

My first attempt used the Android app ClockSync. It's an NTP client, mainly for rooted phones, but it also offers an assisted mode for setting time manually. It can be configured to check an NTP server periodically and and post a notification with the offset, if the offset is more than +/- 1 second. Tasker can grab the notification and extract the offset value, no problem. However, if the next check finds the offset is, for instance, just 0.9 seconds, there is no notification, so the value isn't updated. I can work around that by using a timer and setting the offset to zero if the notification doesn't appear when it should. But that's not really satisfactory. In my example, the actual offset is much closer to 1 than to 0.

My next thought was to use the web site, http://time.is/ which reports the local time offset, along with the correct time, using javascript. But as far as I can tell, there is no way in Tasker to render that page and extract the needed data.

So far, the best suggestion I've seen is to load headers from google.com and compare the Date stamp with the phone's system time. I think I could make that work, but the accuracy would be no better that +/- 1 second. I'd like to do better, if possible. Any ideas?

Thanks for any suggestions!


Reply all
Reply to author
Forward
0 new messages