Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gpasq
Visitor

Dates from JSON milliseconds

I have JSON from a service that has dates in milliseconds since epoch. For example:

{"AuthResponse":{"Token":"2ae659bb-3661-4250-ba4d-066bb814asdf3d","Expiration":1385396952932}}

But it appears that the JSON parser cannot deal with a number that large. I saw the post about using roRegEx to convert that to a string, which works just fine, but I still have no way to get a date from that string. Any ideas?
0 Kudos
4 REPLIES 4
destruk
Streaming Star

Re: Dates from JSON milliseconds

You will probably need to truncate the milliseconds, as it only deals with integer seconds for this.
value=FIX(value/1000) will do the truncation.

roDateTime makes it easy.

fromSeconds(Integer numSeconds)
• Initialize the date/time value using the number of seconds from epoch.

http://sdkdocs.roku.com/display/sdkdoc/ifDateTime


From your example it looks like it's using seconds since epoch already, not milliseconds as you stated -
http://www.unixtimestamp.com/index.php
0 Kudos
gpasq
Visitor

Re: Dates from JSON milliseconds

That's a millisecond time.

The part that's missing is that can't just divide the milliseconds by 1000. The JSON/Regex conversions converts the MS to a string. You can't convert the string to an integer, it's too big. You have to convert it to a float, _then_ divide by 1000, then convert back to an int. Finally you can load the date with the now-converted-to-integer seconds.
0 Kudos
TheEndless
Channel Surfer

Re: Dates from JSON milliseconds

"gpasq" wrote:
That's a millisecond time.

The part that's missing is that can't just divide the milliseconds by 1000. The JSON/Regex conversions converts the MS to a string. You can't convert the string to an integer, it's too big. You have to convert it to a float, _then_ divide by 1000, then convert back to an int. Finally you can load the date with the now-converted-to-integer seconds.

Since you're already converting it to a string, why not just trim the last three digits off of the string before converting it back to an int?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
gpasq
Visitor

Re: Dates from JSON milliseconds

"TheEndless" wrote:
"gpasq" wrote:
That's a millisecond time.

The part that's missing is that can't just divide the milliseconds by 1000. The JSON/Regex conversions converts the MS to a string. You can't convert the string to an integer, it's too big. You have to convert it to a float, _then_ divide by 1000, then convert back to an int. Finally you can load the date with the now-converted-to-integer seconds.

Since you're already converting it to a string, why not just trim the last three digits off of the string before converting it back to an int?


LOL... I had not thought of that!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.