Hi,
I have time series given in gregorian time in seconds since 1992-01-01 00:00:00'. For example; 23853938,23853939...
How can i convert this gregorian time seconds to decimal years like 2010.544, 2010.545...

 採用された回答

Walter Roberson
Walter Roberson 2021 年 5 月 10 日

0 投票

basetime = datetime('1992-01-01 00:00');
gtime = 23853938
t1 = basetime + seconds(gtime)
t2 = dateshift(t1, 'start', 'year')
t3 = dateshift(t1, 'end', 'year')
fy = year(t1) + (t1-t2)./(t3-t2)

4 件のコメント

Walter Roberson
Walter Roberson 2021 年 5 月 10 日
This assumes fraction of actual year, taking into account leap year, not fraction of fixed length year.
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK 2021 年 5 月 10 日
編集済み: Walter Roberson 2021 年 5 月 10 日
it is giving similar results as I did actually, what I do is;
T = datetime(1992,1,1) + seconds(gtime);
T.Format = 'yyyy-MM-dd HH:mm:ss';
dy = decyear(T)
both are correct, I guess :) Thank you in advance
Walter Roberson
Walter Roberson 2021 年 5 月 10 日
decyear() appears to require the Areospace Toolbox.
Also, setting the Format is not required for decyear()
Will
Will 2024 年 11 月 18 日
編集済み: Will 2024 年 11 月 18 日
This won't match decyear() as (t3-t2) is not the exact length of the year. decyear() calculates the fractional year as (t1-t2)/(number of hours in year or leap year).
Without the aerospace toolbox you can use:
t3 = t2 + calyears(1);
fy = year(t1) + (t1-t2)./(t3-t2)
or with dateshift(), shift to the equivalent time in the year before or after to get the correct length duration, e.g.
t3 = dateshift(t1, 'end', 'year')
t4 = dateshift(datetime(year(t1)-1,1,1), 'end' ,'year');
fy = year(t1) + (t1-t2)./(t3-t4)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2021 年 5 月 9 日

編集済み:

2024 年 11 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by