MATLAB: How to get datetime with the “Epoch” key to millisecond resolution

datetimemillisecond

I have two dates, date1 and date2, presented as the number of seconds (up to the millisecond acuracy) since Jan 01, 2020. I want them to convert to a datetime object with the resolution also up to a millisecond, but cannot do it. Specifically:
date1=21108340.851;
Conversion:
t1 = datetime(date1,'ConvertFrom','epochtime','Epoch','2020-01-01','Format','dd-MMM-uuuu HH:mm:ss.sss')
t1 =
datetime
01-Sep-2020 07:25:40.040
date2=21108340.751; % note, it is 0.1 s earlier, so I expect the conversion to the datetime will be 0.1 s earlier, as well.
t2 = datetime(date2,'ConvertFrom','epochtime','Epoch','2020-01-01','Format','dd-MMM-uuuu HH:mm:ss.sss')
t2 =
datetime
01-Sep-2020 07:25:40.040
Why is t2=t1?

Best Answer

t1 = datetime(date1,'ConvertFrom','epochtime','Epoch','2020-01-01','Format','dd-MMM-uuuu HH:mm:ss.sss')
For datetime objects, the format to represent fractions of a second is SSS not sss