Parse Timestamp with milliseconds from HTTP GET request

11 views (last 30 days)
Hi. I am using a REST api where I get timestamps looking like this:
12(1),2022-09-15 00:00:00,2022-09-15 00:16:09.264,2022-09-14 00:00:00,94.100000000000
12(1),2022-09-15 19:44:50.559,2022-09-15 19:44:50.650,2022-09-15 00:00:00,90.840000000000
12(1),2022-09-16 19:47:06.936,2022-09-16 19:47:07.113,2022-09-16 00:00:00,91.350000000000
12(1),2022-09-19 19:50:21.285,2022-09-19 19:50:21.455,2022-09-19 00:00:00,92.000000000000
12(1),2022-09-20 19:46:47.152,2022-09-20 19:46:47.298,2022-09-20 00:00:00,90.620000000000
When reading this using matlab.net.http.RequestMessage and acceptType as text/csv, the timestamps with millisecond precision are just converted to "NaT".
MATLAB gives:
12(1),2022-09-15 00:00:00,NaN,2022-09-14 00:00:00,94.1
12(1),NaT,NaN,2022-09-15 00:00:00,90.84
12(1),NaT,NaN,2022-09-16 00:00:00,91.35
12(1),NaT,NaN,2022-09-19 00:00:00,92
12(1),NaT,NaN,2022-09-20 00:00:00,90.62
How can I control this parsing so it understand the timestamps?
According to this: HTTP Data Type Conversion - MATLAB & Simulink - MathWorks Nordic , it uses "readtable" underneath. This is what I want. If I try readtable locally from a file, and specify "datetime" in delimitedTextImportOptions as the VariableType, then the conversion works. So the format is recognized.
Surely there must be some way to control this so it is always recognized...

Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by