how to convert string to a daily datetime?

26 次查看(过去 30 天)
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,19:56
DateTime = datetime('1900-01-01 00:00:00') + Time/24;
  2 个评论
Steven Lord
Steven Lord 2024-11-12,20:19
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by