I'm using core JSON api to POST/PATCH data from an Android App to my Drupal 8 site. When I need to fill a datetime field I use the next JSON, for example, 2020-02-20T13:15:00. But with this format, this time is UTC, but I need Europe/Madrid timezone. How should I do it?

  • 1
    All dates are stored in UTC within Drupal, so you should be sending the API UTC dates. So it sounds like you probably need to convert your date into UTC within your app before sending to drupal
    – Leigh
    Feb 20, 2020 at 12:13

1 Answer 1


In DateTimeNormalizer, the inferface format is RFC3339, which is Y-m-d\TH:i:sP as an input format string. It also accepts the ISO8601 PHP string, which is Y-m-d\TH:i:sO

Try using strings like in your request '2020-02-20T13:15:00+01:00'.

What I suspect is happening, is that since you aren't specifying the UTC offset, it is being interpreted as '+00:00'

The denormalizer also allepts a format string with the request to parse the value. I believe it is called format

See also DateTimeNormalizerTest and EntityTestDatetimeTest for some more examples.

  • Thanks, I'll try it and I'll check it if it works.
    – briast
    Feb 20, 2020 at 16:29
  • I have a question. In Spain we have two timezone. In winter +1h but in summer +2h (we have to add an hour the next March, 29). Then, should I post +2:00 in summer and +01:00 in winter?
    – briast
    Feb 21, 2020 at 7:31
  • @briast The proper way is to generate a date/time object on the host that is doing the post and then render it out in the proper format, which will then append the proper offset string. In PHP it would be something like $value = $date->format('c') or $value = $date->format('Y-m-d\TH:i:sP').
    – mpdonadio
    Feb 21, 2020 at 13:38
  • Thanks for your answer. I have to do it in my android App.
    – briast
    Feb 22, 2020 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.