Changing gregorian date number to calendar date and time

77 visualizaciones (últimos 30 días)
Arun Nair
Arun Nair el 6 de Dic. de 2019
Comentada: Akira Agata el 1 de Dic. de 2020
I have an 18 years monthly data, whose 'time' variable is in gregorian calender. How do I change this to YYYY-MM format
More details about the variable:
units = hours since 1900-01-01 00:00:00.0
long_name = time
calendar = gregorian
For reference this is what time(1) looks like
>> time(1)
ans =
876582

Respuesta aceptada

Akira Agata
Akira Agata el 6 de Dic. de 2019
If your time vector represents hours since 1900-01-01 00:00:00.0 , following code can convert it into yyyy-MM-dd.
T = datetime(1900,1,1) + hours(time);
T.Format = 'yyyy-MM-dd';
  3 comentarios
Carrie Merritt
Carrie Merritt el 1 de Dic. de 2020
what if you have, say, 3 hourly data instead of monthly?
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
Akira Agata
Akira Agata el 1 de Dic. de 2020
The same process should work:
% Sample time vector
time = [176064; 176067; 176070];
% Convert to datetime vector
T = datetime(1900,1,1) + hours(time);
% Set the display format to show hours
T.Format = 'yyyy-MM-dd HH:mm:ss';
>> T
T =
1920-02-02 00:00:00
1920-02-02 03:00:00
1920-02-02 06:00:00

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