Changing gregorian date number to calendar date and time

18 ビュー (過去 30 日間)
Arun Nair
Arun Nair 2019 年 12 月 6 日
コメント済み: Akira Agata 2020 年 12 月 1 日
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

採用された回答

Akira Agata
Akira Agata 2019 年 12 月 6 日
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 件のコメント
Carrie Merritt
Carrie Merritt 2020 年 12 月 1 日
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 2020 年 12 月 1 日
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

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by