converting from integer time to datetime in 3-hourly data

I've tried everything I can think of to convert from integer time to datetime. Anyone have any intuitions or suggestions? Thanks!
time
Size: 13208x1
Dimensions: record
Datatype: double
Attributes:
standard_name = 'time'
long_name = 'Time'
units = 'hours since 1979-12-01 00'
time_calendar = 'gregorian'
start = '1979120100'
step = '3'
With having a time step of '3' I'm not sure how to apply the datetime function.
For reference:
>> time(1)
ans =
176064

댓글 수: 6

Here's one thing I've been trying to make work:
T = datetime(1979,12,1) + hours(time);
T.Format = 'yyyy-mm-dd-HH'
Simple enough, but gives me:
>> T(1)
ans =
datetime
2000-00-01-00
The output I need should look like: 1980-12-01-00
My answer moved here:
X = {'1979120100', '1979120103', '1979120106'}
T = datetime(X,'InputFormat','yyyyMMddhh','Format','yyyy-MM-dd HH:mm')
result is:
T =
1×3 datetime array
1979-12-01 00:00 1979-12-01 03:00 1979-12-01 06:00
Some calculation:
>> T(3)-T(1)
ans =
duration
06:00:00
Carries comment moved here:
Hi Stephan,
Thanks for the response. If you notice, I referenced the first time integer (e.g., time(1) = 176064). The method you have suggested assumes I already have a time vector in the 'yyyyMMddHH' format. Which I do not. It is what I need though.
I'm not sure what kind of time units I'm working with aside from what information I have in the netCDF file.
I see, can you attach the data object you have there?
Stephan
Stephan 2020년 12월 1일
편집: Stephan 2020년 12월 1일
Carries comment moved here:
Please see attached. There isn't anything on the script aside from my numerous failed attempts at trying to make this work. All I'm trying to do is read the time in and convert it from its original netCDF format to a date/time format.
Is it possible that the first time should be 05-Jun-1982 ?

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephan
Stephan 2020년 12월 2일
편집: Stephan 2020년 12월 2일
Heres an approach:
I believe the idea behind this:
is that the integer values start counting by
1979-12-01 00:00 --> 0
1979-12-01 03:00 --> 3
1979-12-01 06:00 --> 6
If this assumption would be correct:
data = ncread('EasterlyOneYear850.nc','time');
time_new = datetime('1979-12-01 00:00') + hours(data);
Should give you the correct time values in your data:
time_new(1:3)
gives then:
ans =
3×1 datetime array
01-Jan-2000 00:00:00
01-Jan-2000 03:00:00
01-Jan-2000 06:00:00
So we end up that your data could have started exactly by millenium and ends here:
>> time_new(end)
ans =
datetime
31-Dec-2000 21:00:00
which is the last possible value in the year 2000, since the next one would be in the year 2001.
Can this be correct?

댓글 수: 3

I cannot make the numbers work out to that unless the first date should instead be 1982-06-05 (05-Jun-1982)
Ok, i missed that.
So sorry I never followed up on this! Yes, so it turns out the starting time is 2000-01-01-00 and ending time is 2000-12-31-21. The issue was that I was under the assumption that my collaborator who gave me this tracking data/file, was using the full MERRA-2 period (starting in 1980). After confirming with her, this particular file was just for 2000. Yeesh. This is why attribute data is always important, right?! Thanks so much for the help on this and I will be sure to remember to come back to this answer if I ever run into the same issue without having access to author of the file. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2020년 12월 1일

댓글:

2021년 4월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by