- json_encode: documentation ( source)
<?php
class SerialDateTime extends DateTime implements JsonSerializable{
public function jsonSerialize(){
return ['timestamp' => $this->getTimestamp()];
}
public static function createFromFormat(){
$a = call_user_func_array(array(__CLASS__ , 'parent::'.__METHOD__), func_get_args());
return new self($a->getTimestamp());
}
}
echo json_encode([SerialDateTime::createFromFormat('m/d/Y', '10/31/2011')]);