How to get datetime with the "Epoch" key to millisecond resolution
7 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Walter Roberson
2020-9-18
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!