[racket] JSON datetime value?
(sorry for the duplicate)
JSON doesn't specify a way of encoding dates. See http://json.org/
You have to convert your date to a string first, like this:
racket> (jsexpr->string (date->string (current-date)))
"\"Sat Jan 05 11:20:35-0700 2013\""
Your Javascript code can then just parse the JSON string:
javascript> new Date("Sat Jan 05 11:20:14-0700 2013")
Sat Jan 05 2013 11:20:14 GMT-0700 (MST)
javascript> new Date("Sat Jan 05 11:20:14-0700 2013").getFullYear()
2013
Or you can convert your date to a dictionary or something. It depends on
how your application parses dates.
Limbo Peng <iwinux at gmail.com> writes:
> Hi,
>
> I want to convert some datetime values to JSON, but the json library
> doesn't seem to support it:
>
> (require srfi/19)
> (require json)
> (jsexpr->string (current-date))
> ; it complains:
> ;; write-json: expected argument of type <bad JSON value>
> ;; given: (tm:date 561000000 33 12 1 6 1 2013 28800)
>
> What would be the appropriate way to do it?
> BTW: should I use library "srfi/19" or "date" when dealing with datetime?
>
> Thanks in advance.
>
> -Limbo Peng
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users