Correcting timestamp from netCDF

6 次查看(过去 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,

采纳的回答

Peter Perkins
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.
  1 个评论
George Lavidas
George Lavidas 2018-8-8
Peter thank you very much for this answer, this is quite different and much faster from I had been using thanks.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by