How to keep the precision of datetime when taking into consideration time offsets
Show older comments
I am writing a code that will convert the time into different readable (plotable) formats. For instance I have data that is reported in milliseconds, I would like to convert it to a 'HH:mm:ss.SSS' format. I am able to write code to do this. The issue is when I take into consideration a time offset, in a format 'HH:mm:ss.SSS', I lose the millisecond detail. Below is part of my code, I cannot share all of it.
if nargin < 4
pTimeOffsets = datetime('00:00:00.000',...
'Format','HH:mm:ss.SSS'); % this is the Time Offset, it is an optional argument and if left out is defaulted to nothing.
end
...
pConvertedTime = datetime(strcat(string(lHH),':',...
string(lmm),':',...
string(lss),'.',...
string(lSSS)),...
'Format','HH:mm:ss.SSS'); % this will take the milliseconds and convert into a datetime object.
%The desired precision is kept.
If I were to do this:
pConvertedTime = datetime(strcat(string(lHH),':',...%lHH is hour number
string(lmm),':',...%lmm is minute number
string(lss),'.',...%lss is second number
string(lSSS)),...%lSSS is millisecond number
'Format','HH:mm:ss.SSS') - pTimeOffsets; % offsets loses milliseconds precision
Any suggestions?
2 Comments
dpb
on 11 Dec 2019
Provide a minimum working example that illustrates the problem, please...
John Steiner
on 11 Dec 2019
Edited: John Steiner
on 11 Dec 2019
Accepted Answer
More Answers (1)
John Steiner
on 11 Dec 2019
0 votes
Categories
Find more on Dates and Time 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!