- date_default_timezone_set: documentation ( source)
- json_encode: documentation ( source)
<?php
date_default_timezone_set('America/Los_Angeles');
class Fruit implements JsonSerializable {
public
$type = 'Apple',
$lastEaten = null;
public function __construct() {
$this->lastEaten = new DateTime();
}
public function jsonSerialize() {
return [
'type' => $this->type,
'lastEaten' => $this->lastEaten->format(DateTime::ISO8601)
];
}
}
echo json_encode(new Fruit());
echo json_encode(DateTime);