Represent CDF Time Values
This example shows how to extract date information from a CDF epoch object. CDF represents time differently than MATLAB®. CDF represents date and time as the number of milliseconds since 1-Jan-0000. This is called an epoch in CDF terminology. To represent CDF dates, MATLAB uses an object called a CDF epoch object. MATLAB also can represent a date and time as a datetime value or as a serial date number, which is the number of days since 0-Jan-0000. To access the time information in a CDF object, convert to one of these other representations.
Read the sample CDF file, example.cdf
.
data = cdfread('example.cdf');
whos
Name Size Bytes Class Attributes data 24x6 23904 cell
cdfread
returns a cell array.
Extract the date information from the first CDF epoch object returned in the cell array, data
, using the todatenum
function.
m_datenum = todatenum(data{1})
m_datenum = 730852
Convert the MATLAB serial date number to a datetime value.
m_datetime = datetime(m_datenum,'ConvertFrom','datenum')
m_datetime = datetime
01-Jan-2001