$date = DateTime::createFromFormat('Y-m-d H:i:s', '2012-06-06 18:05:21'); // your original DTO
$newFormat = $date->format('Y,m,d,H,i,s'); // your newly formatted date ready to be substituted into JS new Date();
unset($date);
$json = json_encode(["start" => $newFormat, 'content' => "Start Date"]);
在 JS 中你可以做某事。如同:
var objectFromJSON = some_json_decode_procedure(); // decoding JSON to native object
var dateArray = objectFromJSON.start.split(','); // splitting string to elements for new Date()
objectFromJSON.start = new Date(dateArray[0], dateArray[1], dateArray[2], dateArray[3], dateArray[4], dateArray[5]); // resetting Date() object in the object