how to convert string to a daily datetime?

I extracted the time array from (nc file), its a daily time arry for the year 1979, and below is sample of the extracted data.
The description of the nc file gave the following below details.
Can any one help me to convert the string numbers to the a datetime arry ?
Sample of the data
Time=[ 692496 692520 692544 692568 692592 692616 692640 692664 692688 692712 692736 692760 692784 692808 692832 692856 692880 692904 692928 692952 692976 693000 693024 693048 693072 693096 693120 693144 693168 693192 693216 693240 693264 693288 693312 693336 693360 693384 693408 693432 693456 693480 693504 693528 693552 693576 693600 693624 693648 693672 693696 693720 693744 693768 693792 693816 693840 693864 693888 693912 ]
Description of nc file about the time array
time
Size: 365x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
axis = 'T'
standard_name = 'time'
coordinate_defines = 'start'
actual_range = [692496 701232]
delta_t = '0000-00-01 00:00:00'
avg_period = '0000-00-01 00:00:00'
units = 'hours since 1900-01-01 00:00:00'

 채택된 답변

Walter Roberson
Walter Roberson 2024년 11월 12일

0 개 추천

DateTime = datetime('1900-01-01 00:00:00') + Time/24;

댓글 수: 2

sherien
sherien 2024년 11월 12일
it works well, thanks alot
Or taking advantage of the units description to make the code look closer to that description:
Time=[ 692496 692520 692544 692568 692592 692616 692640 692664 692688 692712 692736 692760 692784 692808 692832 692856 692880 692904 692928 692952 692976 693000 693024 693048 693072 693096 693120 693144 693168 693192 693216 693240 693264 693288 693312 693336 693360 693384 693408 693432 693456 693480 693504 693528 693552 693576 693600 693624 693648 693672 693696 693720 693744 693768 693792 693816 693840 693864 693888 693912 ];
dt1 = hours(Time) + datetime(1900, 01, 01); % 'hours since 1900-01-01 00:00:00'
dt2 = datetime('1900-01-01 00:00:00') + Time/24;
isequal(dt1, dt2)
ans = logical
1

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

질문:

2024년 11월 12일

댓글:

2024년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by