title: Custom datetime format from DB in JMSSerializerBundle
body: <p>I have a simple problem but I have no idea how to solve it.</p>
  
  <p>I have a project in Symfony2 with FOSRestBundle + JMSSerializerBundle.
  In my entities, I've got some datetime fields, and the user should be able to define the format of the datetime retrieved by the API, as you can see :</p>
  
  <p><a href="https://i.stack.imgur.com/dpKYQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dpKYQ.png" alt="Input to define the datetime format"></a></p>
  
  <p>My problem is that I don't know how to tell JMSSerializerBundle to use the user-defined format for my datetime fields.
  Currently I have this :</p>
  
  <pre><code>/**
   * @var \DateTime
   *
   * @ORM\Column(name="custom_date", type="datetime")
   * @Serializer\Type("DateTime&lt;Y-m-d&gt;")
   * @Serializer\Expose
   */
  protected $custom_date;
  </code></pre>
  
  <p>The only way I found is to use the VirtualProperty method from JMSSerializerBundle, but it means that my entity <strong>must</strong> have a relation with the user.
  Something like that :</p>
  
  <pre><code>/**
   * @Serializer\VirtualProperty
   * @Serializer\Type("string")
   * @Serializer\SerializedName("custom_date")
   */
  public function getVPCustomDate() {
      $format = $this-&gt;user-&gt;getSetting('date_format');
      return $this-&gt;custom_date-&gt;format($format);
  }
  </code></pre>
  
  <p>But it wouldn't make sense to do it that way, so I hope you have some alternatives!</p>
  
  <p>Thanks for your time and your help.</p>