www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CalculateElapsedTimesOnDSTShiftExample.m
%% Calculate Elapsed Times on DST Shift % Calculate elapsed times since midnight on a day with a Daylight Saving % Time (DST) shift. % % Create a |datetime| array. Set its |TimeZone| property to a time zone % that observes DST. Set the date to a date when a DST shift occurred. % Copyright 2015 The MathWorks, Inc. tz = 'America/New_York'; fmt = 'dd-MMM-yyyy HH:mm:ss z'; t = datetime(2015,3,8,'TimeZone',tz,'Format',fmt) + hours(1:4) %% % Calculate the elapsed times. The DST shift occurred at 02:00 on March 8, % 2015 in this time zone. |timeofday| accounts for the shift for times % at or after 02:00 on this date. d = timeofday(t)