Forum Discussion

gpasq's avatar
gpasq
Visitor
12 years ago

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?

4 Replies

  • destruk's avatar
    destruk
    Streaming Star
    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
  • 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.
  • "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?
  • "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!