1

I see that .NET can encode the dates like /Date(1365004652303-0500)/ when it generate the JSON response for a RestFull API response (for example read here).

My question is how can I generate the same output for my date properties inside an object when I use json_encode function to encode that object in the PHP.

I don't mean how to do it with an algorithm. I know how to write the algorithm! I would like to do it in a way that the front-end could understand this property is a date! I don't want to transfer it as a simple text!

MJBZA
  • 4,796
  • 8
  • 48
  • 97
  • 1
    Does this help? https://stackoverflow.com/questions/10286204/the-right-json-date-format – O. Jones Mar 29 '20 at 10:30
  • How can I force the `json_encode` to generate the requested format from Date objects? I cannot find a clear answer there. I don't care about human readable dates! I want machine recognizable dates in my API response. – MJBZA Mar 29 '20 at 10:34
  • Somebody there said `What .NET does is a non-standard hack/extension.` So does it mean it is not a good idea to have such a format?? – MJBZA Mar 29 '20 at 10:39
  • 1
    JSON support 6 types on data: `string`, `number`, `boolean`, `null`, `object`, `array`. No `date` type for you, sir :) – Yevgen Mar 29 '20 at 10:46
  • Yes, It seems this is not a good format in general. – MJBZA Mar 29 '20 at 10:47

0 Answers0