www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CompareTwoDatetimesExample.m

    %% Compare Two Datetime Values
% Determine if midnight on January 13, 2013 in Anchorage, Alaska is equal to
% 11 AM on the same date in Cairo.

% Copyright 2015 The MathWorks, Inc.

t1 = datetime(2013,1,13,0,0,0,'TimeZone','America/Anchorage');
t2 = datetime(2013,1,13,11,0,0,'TimeZone','Africa/Cairo');
tf = isequal(t1,t2)
%%
% Add 8 months to the date, and compare the datetime values for equality.
t1 = datetime(2013,9,13,0,0,0,'TimeZone','America/Anchorage');
t2 = datetime(2013,9,13,11,0,0,'TimeZone','Africa/Cairo');
tf = isequal(t1,t2)
%%
% The datetime values are no longer equal since Cairo does not observe daylight
% saving time.