How to change datenum to normal date format?

5 次查看(过去 30 天)
Hi all,
I have tried using following command but as a result date has wrong year and they are not in sequence too:
datestr(A{1})
>>'01-Jul-4447'
'25-Jul-4447'
'18-Aug-4447'
'11-Sep-4447'
'05-Oct-4447'
'29-Oct-4447'
datetime(A{1}, 'ConvertFrom', 'datenum', 'Format', 'dd-MM-yyyy')
>>01-07-4447
25-07-4447
18-08-4447
11-09-4447
05-10-4447
29-10-4447
datevec(A{1})
>>4447 7 1 0 0 0
4447 7 25 0 0 0
4447 8 18 0 0 0
4447 9 11 0 0 0
4447 10 5 0 0 0
4447 10 29 0 0 0
I have attached a dummy data here in this link:

回答(2 个)

Walter Roberson
Walter Roberson 2021-2-26
filename = 'olr_1985.nc';
times = hours(ncread(filename, 'time')) + datetime(1800,1,1, 'format', 'yyyy-MM-dd hh:mm');
Results are 1985-01-01 12:00 to 1985-04-30 12:00
  1 个评论
UTKARSH VERMA
UTKARSH VERMA 2021-3-9
Hi Walter,
I tried above code but the results are different to what you have mentioned:
'1806-03-03 08:30'
'1806-03-03 09:30'
'1806-03-03 10:30'
'1806-03-03 11:30'
'1806-03-03 12:30'

请先登录,再进行评论。


ANKUR KUMAR
ANKUR KUMAR 2021-2-26
You can use this function from the matlab file exchange to read time from a ncetcf file in user specified format: https://in.mathworks.com/matlabcentral/fileexchange/87894-ncreadtime
An example is shown below using the file you attached:
file='olr_1985.nc'
ncreadtime(ncread(file,'time'),ncreadatt(file,'time','units'),'yyyymmdd_HH')

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by