I can't get millisecond accuracy from string based timestamp - not sure what I'm doing wrong
Show older comments
I have a load of data that's timestamped that I'm looking to manipulate using mainly durations. Issue is that the data is in 3 digit millisecond precisions and nothing less precise will do and everytime I try to convert my string cells to timestamps, it round everything to the nearest second and adds the current date to the front. I don't actually need the date at all.
This is my raw input, its a cell array of timestamps.
My code:
> infmt = 'HH:mm:ss.SSS';
> formatted_timestamps = datetime(raw_timestamps, 'InputFormat', infmt);
My output:

I have tried appending the values with less millisecond digits with zeros to ensure they're all the same length as strings, but all that did was remove the NaT values in output. I have spent hours trying to figure it out but all the forums and support docs say that what I have done is correct and as no on e else appears to have this issue I'm assuming its perhaps something more fundamental that I'm doing wrong?
Thanks in advance!
Accepted Answer
More Answers (1)
If you don't have date information associated with your timestamps, I would use duration instead of datetime.
S = ["11:00:00.147"; "11:00:00.668"; "11:00:00.932"; "11:00:04"]
fmt = 'hh:mm:ss.SSS';
d = duration(S, 'InputFormat', fmt)
d2 = duration(S, 'InputFormat', fmt, 'Format', fmt)
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!