Conversion of Gregorian date to decimal years

22 visualizaciones (últimos 30 días)
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK el 9 de Mayo de 2021
Editada: Will el 18 de Nov. de 2024 a las 16:44
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...

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Mayo de 2021
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 comentarios
Walter Roberson
Walter Roberson el 10 de Mayo de 2021
decyear() appears to require the Areospace Toolbox.
Also, setting the Format is not required for decyear()
Will
Will el 18 de Nov. de 2024 a las 16:39
Editada: Will el 18 de Nov. de 2024 a las 16:44
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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by