gpasq
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2013
09:47 AM
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?
{"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?
4 REPLIES 4
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2013
10:25 AM
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
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
gpasq
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2013
10:51 AM
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.
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.

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2013
12:48 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
gpasq
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2013
10:23 AM
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!