-->

Format returning date format on Symfony2 FOSRestBu

2019-08-15 12:19发布

问题:

Is there any way to change the returning date format on a Webservice built with FOSRestBundle in Symfony2?

For example, this is my actual return:

{"id":9,"nome":"Guilherme","rg":"0000000000","cpf":"000.000.000-00","nascimento":"1989-06-24T00:00:00+0200","genero":"M"}

I want to change to this:

{"id":9,"nome":"Guilherme","rg":"0000000000","cpf":"000.000.000-00","nascimento":"1989-06-24","genero":"M"}

Thanks.

回答1:

It's just to add this annotation to the property:

@Type("DateTime<'Y-m-d'>")

See more: http://jmsyst.com/libs/serializer/master/reference/annotations#type