Is somehow possible to change output of json_encode([\'date\' => $dateTimeObj])
?
Now it prints
{
\"date\": {
\"date\":
After changing a few details, notably the interface name, your code works just fine for me on PHP 7.0.14.
<?php
class MyDateTime extends \DateTime implements \JsonSerializable
{
public function jsonSerialize()
{
return $this->format("c");
}
}
$datetime = new MyDatetime();
$output = [
'date' => $datetime,
];
echo json_encode($output);
// Outputs: {"date":"2017-02-12T17:34:36+00:00"}