I am trying to convert the following datetime into string format in Matlab.
20121003.03
It corresponds to 3rd Oct 2012, 03:00am. Any ideas?
I am trying to convert the following datetime into string format in Matlab.
20121003.03
It corresponds to 3rd Oct 2012, 03:00am. Any ideas?
You can specify a custom input format when creating a datetime object. Your question seems to indicate that the object is already a datetime object, but at that point the problem is trivial, just call datestr on it (the last line of the script below). I'll assume here that the input is a floating point representation.
dval = 20121030.0330;
% Convert floating point number to a string
dstr = sprintf('%013.04f', dval);
% Convert string to a datetime object
dtime = datetime(dstr, 'InputFormat', 'yyyyMMdd.hhmm');
% Convert the datetime object into a formatted string
dstr2 = datestr(dtime);
Output:
dstr2 = '30-Oct-2012 03:00:00'
If you want an output format different than the default then you need to specify the output format of datestr. See the documentation for more information.