Changing gregorian date number to calendar date and time
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arun Nair
am 6 Dez. 2019
Kommentiert: Akira Agata
am 1 Dez. 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
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 6 Dez. 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 Kommentare
Carrie Merritt
am 1 Dez. 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
am 1 Dez. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!