Azzera filtri
Azzera filtri

Correcting timestamp from netCDF

6 visualizzazioni (ultimi 30 giorni)
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,

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by