Я ищу способ форматирования даты, заданной из json-ответа. В настоящее время я могу передать дату с помощью реакции JSon в оба формата:Формат даты, заданной json
формат строки:
{"date":"2016-11-25T11:24:54+0100"}
или формат объекта:
"date":{"timezone":{"name":"Europe\/Paris","location":{"country_code":"FR","latitude":48.86666,"longitude":2.33333,"comments":""}},"offset":3600,"timestamp":1480069808}}
я должен форматировать один из этих двух форматов JSon в этот формат: dd/mm/aaaa
, пример: 25/11/2016
Эта операция должна выполняться на мой взгляд с помощью jQuery/js или в контроле г, прежде чем отправить JSon réponse:
/* $normalizer = new GetSetMethodNormalizer(); here the code for fomat the date into string
$callback = function ($dateTime) {
return $dateTime instanceof \DateTime
? $dateTime->format(\DateTime::ISO8601)
: '';
};
$normalizer->setCallbacks(array('date' => $callback));*/
$normalizer->setIgnoredAttributes(array('article'));
$serializer = new Serializer(array($normalizer), array($encoder));
$dataJSON = $serializer->serialize($data, 'json');
$response = new Response();
$response->setContent($dataJSON);
$response->headers->set('Content-Type', 'application/json');
return $response;