MATLAB: Convert string array to datetime

datetime

I am trying to convert a string in the format seen below into a datetime:
"2016-07-22 10:02:54.087216500-04:00"
I have had a look at the MATLAB documentation and tried the following:
datetime(ans, 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss.SSSSSSSSSXXX', 'TimeZone', 'America/New_York')
I receive the following error however:
"Unable to convert the text to datetime using the format 'yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSXXX'."
I am not actually sure that the timezone is New York, as I pulled the data from the internet and there was no indication of this. It was the only one in the list found in the MATLAB help under the "TimeZone" section of the "datetime" help that had -04:00 however, so I assumed that it would be this.
Can someone see where my mistake in understanding the format of the date is? If so please could you provide a solution that will help me read this format of string into a datetime?
Thanks!

Best Answer

Yes, there's no 'T' in your input so the format should be 'yyyy-MM-dd HH:mm:ss.SSSSSSSSSXXX'
>> s = "2016-07-22 10:02:54.087216500-04:00";
>> datetime(s, 'InputFormat', 'yyyy-MM-dd HH:mm:ss.SSSSSSSSSXXX', 'TimeZone', 'America/New_York', 'Format', 'dd MMM yyyy HH:mm:ss z')
ans =
datetime
22 Jul 2016 10:02:54 EDT
I'm overriding the display format in the above. This is of course optional.