MATLAB: Convert julian date SAC to specific format date

julian date to format date yyyymmdd

I need convert: CM.SJC..HHE.D.2015.213.172556.SAC to specific format date, examples: 2015 7 26
Please

Best Answer

S = 'CM.SJC..HHE.D.2015.213.172556.SAC';
parts = regexp(S,'\.','split');
year = str2double(parts{6});
doy = str2double(parts{7});
hour = str2double(parts{8}(1:2));
minute = str2double(parts{8}(3:4));
second = str2double(parts{8}(5:6));
output = datetime(year, 1, 1, hour, minute, second, 'Format', 'yyyy M d hh:mm:ss', 'timezone','utc') + days(doy);
output
output = datetime
2015 8 2 05:25:56
days(datetime(2015,7,26)-datetime(2015,1,1))
ans = 206
Could you confirm that you really do have Julian days? Julian Days are number of days since a particular date around 4700 BCE. As you can see, there is a difference of exactly one week between your intended output and a calculation based upon day of the year.