MATLAB: Datetime Invalid Parameter for TimeZone

datetimegmtposixtimetimezone

Hi,
I need to convert a timestamp to GMT which depends on the TimeZone. This is read out of a variable which was in this case 'Europe/Berlin'. The timestamp has to be sent as a request in GMT time and will be sent back (both as posixtime). The backtransformation from posixtime to the timezone read out of the variable is working:
datetime(1565618481,'TimeZone','Europe/Berlin','ConvertFrom','posixtime',"TicksPerSecond",1000,'Format','dd-MMM-yyyy HH:mm:ss.SSS Z')
For the request I wanted to define a datetime vektor of the local time with the timezone and convert it then to GMT to make the posixtime vektor afterwards. In the following code the same timezone was not working:
datetime('22.07.2019 21:00:00','InputFormat','TimeZone','Europe/Berlin','dd.MM.yyyy HH:mm:ss Z')
I always get the Error:
Error using datetime (line 538)
Invalid parameter name: Europe/Berlin.
Can anyone help me why this is the case and how I can make it work?
Thank you,
Manuel

Best Answer

You need to put the format string just after the 'InputFormat' name (they are ‘name-value pair’ arguments), and also use the 'Z' designator in the time string.
Try this:
tq = datetime('22.07.2019 21:00:00 Z','TimeZone','Europe/Berlin','InputFormat','dd.MM.yyyy HH:mm:ss Z')
producing:
tq =
datetime
22-Jul-2019 23:00:00