MATLAB: Time stamp formatting question MATLABtime stamp Hi everyone – I have a time stamp in the following form : '0d 00:00:5.03000020980835' I am trying to convert it into a vector in hh:mm:ss, any ideas? Best Answer dtstr = '0d 00:00:5.03000020980835'; dtstr = regexprep(dtstr,'\d+d',''); %remove daysdt = datetime(dtstr,'InputFormat','HH:mm:ss.SSS','Format','HH:mm:ss')[update]To preserve the number of days within the hour-count and to account for missing decimals in the seconds,dtstr = {'0d 23:59:58.439998626709''0d 23:59:59''1d 00:00:0''1d 00:00:1.44000005722046''1d 00:00:2.44000005722046''1d 00:00:3.44000005722046'};% Add .0 to time stamps that are missing the decimalnoDecIdx = ~cellfun(@(x)contains(x,'.'),dtstr); dtstr(noDecIdx) = cellfun(@(x)[x,'.0'],dtstr(noDecIdx),'UniformOutput',false);% replace "d " with ":"dtstr = strrep(dtstr,'d ',':'); % Convert to your desired format as durationsD = duration(dtstr,'InputFormat', 'dd:hh:mm:ss.S','Format','hh:mm:ss');Result: 6×1 duration array 23:59:58 23:59:59 24:00:00 24:00:01 24:00:02 24:00:03 Related SolutionsMATLAB: How to convert 5.5 hour to 05:30:00 HH:MM:SS format >> datestr(5.5/24,'HH:MM:SS')ans = 05:30:00 MATLAB: Character to date and time A = { '2012-03-01T00:01:00.000Z' '2012-03-01T00:30:59.999Z' '2012-03-01T01:00:59.999Z' '2012-03-01T01:31:00.000Z' '2012-03-01T02:00:59.999Z' '2012-03-01T02:29:59.999Z' '2012-03-01T03:00:00.000Z'}out = regexprep(A,{'T','Z$'},{' ',''}); Related QuestionHow to defining date formatConverting hh:mm:ss into secondsHow to store multiple time data in a matrixChanging the date format in matlab
Best Answer