Hello,
I have a datasets with time expressed in seconds since 1950-01-01 00:00:00. The two times I would like to convert are : [1907798400] and [1908230400]. I would like to convert them in a date format (Yr-Mnth-Day Hr:min:sec) I previously look on the forum to help me and I did the following steps :
base = datenum(1950,1,1);
datestr([1907798400]/86400) + base)
>> '16-Jun-2010'
base = datenum(1950,1,1);
datestr([1908230400]/86400) + base)
>> '21-Jun-2010'
However, I expect to obtain dates in the months of July 2010. Also, when I open the datasets using Panoply, I obtain the following dates : 2010-07-01 00:00:00 - 2010-07-06 00:00:00. (Yr-Mnth-Day Time)
This is more likely to be what I expect. However, I don't understand why using Matlab I obtain different dates? The year is correct (2010), but not the month. Is there something I am doing wrong?
Could you help me solve this issue?
Thank you a lot for your help.
Regards

 채택된 답변

James Tursa
James Tursa 2018년 4월 11일
편집: James Tursa 2018년 4월 11일

5 개 추천

MATLAB is giving you the result of June 16, 2010 because that is the correct answer for the input of 1907798400. This matches intuition as well, e.g. a crude calculation:
>> (1907798400/86400)/365.25
ans =
60.4545
So you would expect the answer to be 60 years and slightly less than 1/2 year later than the base, which we could easily expect to be in June 2010.
The datetime( ) function also agrees with this:
>> datetime(1950,1,1) + seconds(1907798400)
ans =
datetime
16-Jun-2010 00:00:00
or
>> datetime(1950,1,1,0,0,1907798400)
ans =
datetime
16-Jun-2010 00:00:00
Are you sure you are using the same inputs when you compare the MATLAB results to the Panoply results?

댓글 수: 1

Also:
>> d = datetime([1907798400 1908230400],'ConvertFrom','epochtime','Epoch','01-Jan-1950 00:00:00')
d =
1×2 datetime array
16-Jun-2010 00:00:00 21-Jun-2010 00:00:00

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

추가 답변 (1개)

Valérie Le Guennec
Valérie Le Guennec 2018년 4월 23일

0 개 추천

Hi all, Thank you very much for all your replies. It really helped me. Sincerely

댓글 수: 1

Ozan Akyildiz
Ozan Akyildiz 2019년 2월 11일
Why is this the accepted answer? This is not helping the reader. I suggest Posting the answer you found as an "Answer" then selecting it.

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

카테고리

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

질문:

2018년 4월 11일

댓글:

2019년 2월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by