Correcting timestamp from netCDF
18 次查看(过去 30 天)
显示 更早的评论
Hello to matlab the community,
If possible I would be grateful for some help in regards to conversion of timestamps in matlab from netcdf.
I am familiar with netcdf and their structure as well as their conversion, but I think I am missing something.
I have a netcdf with time in the format of
time =[23627;
23627.0069444444;
23627.0138888889;
23627.0208333333];
And I am trying to correct the timestamp both to a human readable form but also to use in plots.
Of course I checked the time offset in the netcdf and it is in
"days since 1950-01-01T00:00:00Z";
Therefore, I have included this offset in my estimates but I cannot see to be getting the correct form. I am using this
time_offset=datenum(1950,01,01);
new_time=(time/24)+time_offset;
timestamp=datestr(new_time);
timestamp=datestr(new_time,'yyyymmddHHMM');
nt=str2num(timestamp);
timestamp=uint64(nt);
timestamp=double(nt);
However the outcome does not give me what I would expect.
The measurements should be in 10 minute increments like so:
01-01-2015 00:00:00
01-01-2015 00:10:00
The variable is new_time is estimated as
7.132084583333334e+05
that corresponds to the variable timestamp:
195209111100
It seems that it does not recognize the offset. Have I done anything wrong?
Thank you all in advance,
0 个评论
采纳的回答
Peter Perkins
2018-8-3
>> time = [23627 23627.0069444444 23627.0138888889 23627.0208333333];
>> dt = datetime(1950,1,1,'Format','dd-MMM-yyyy HH:mm:ss') + days(time)
dt =
1×4 datetime array
09-Sep-2014 00:00:00 09-Sep-2014 00:09:59 09-Sep-2014 00:20:00 09-Sep-2014 00:29:59
I guess netCDF timestamps are UTC? The above will work for that, in general, you'd want to use caldays to account for DST shifts twice a year.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!