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