Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 

Offset from UTC

is there a way to get the offset of time from UTC in BrightScript? something similar to javascript getTimezoneOffset() http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp ?
0 Kudos
4 Replies
belltown
Level 7

Re: Offset from UTC

"bathejasumeet" wrote:
is there a way to get the offset of time from UTC in BrightScript? something similar to javascript getTimezoneOffset() http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp ?


dt = CreateObject ("roDateTime")
utcHours = dt.GetHours ()
dt.ToLocalTime ()
localHours = dt.GetHours ()
utcOffset = localHours - utcHours
https://github.com/belltown/
0 Kudos
RokuMarkn
Level 7

Re: Offset from UTC

That's a good approach, but it doesn't properly handle timezones which are offset from GMT by a non-integral number of hours. Better to use AsSeconds() rather than GetHours().

--Mark
0 Kudos
belltown
Level 7

Re: Offset from UTC

I was just thinking the same thing, and was just changing my reply as you responded:

dt = CreateObject ("roDateTime")
utcSeconds = dt.AsSeconds ()
dt.ToLocalTime ()
localSeconds = dt.AsSeconds ()
utcSecondsOffset = localSeconds - utcSeconds
utcHoursOffset = utcSecondsOffset / 3600
https://github.com/belltown/
0 Kudos

Re: Offset from UTC

Thanx a lot, the approach worked Smiley Happy
0 Kudos