I’m new to JSON and from what I’ve read it seems pretty difficult to send a date. I need to send several dates using PHP.
I also need to send an image which I’m thinking would be best done using a base64 encoded string. Is there a better way?
Thanks in advance.
JSON itself does not support sending a
Dateobject directly. You can, however, send the timestamp of the date you’re working with as a mere number and useto recreate a
Dateobject. Note here, that PHP uses timestamps based on seconds ( see, e.g., here), whereas JavaScript uses milliseconds as a basis (see, e.g., here)!For images I agree, that sending them in a Base64 encoded form is the best way of doing it, if those images are created dynamically or should not be accessible using a URL.
If they are accessible using a URL, sending this URL instead of the image is, of course, preferable.