MATLAB: How to compare datetime hours across time zones

MATLAB

How do I compare datetime hours across time zones?
I have a Tx1 datetime array in TimeZone="America/New_York'. This specifies dates and times up to the minute. How can I find the indices of those rows which correspond to HH:mm=14:29 in TimeZone="Asia/Tokyo". 

Best Answer

If you want to compare Exact datetime values (With Date) 
This work is already done for you in the "==" operator.
 
nyTime = datetime(2017,1,1,0,0,0,'TimeZone','America/New_York')
% 01-Jan-2017 00:00:00 - America/New_York
tokyoTime = datetime(2017,1,1,14,0,0,'TimeZone','Asia/Tokyo')
% 01-Jan-2017 14:00:00
isSame = nyTime == tokyoTime
% isSame = 1
Compare datetimes by Hour:Minute:Second across time zones (No Date)
If the datetime has defined the "TimeZone" property, the hours will change when you update the TimeZone. Using this, we can create a function that updates the TimeZone to 'UTC' and compares the "timeofday" value.
For example, to find the dates in
 
% dtimes = [T×1 datetime array in TimeZone 'America/New_York']
query = datetime('14:29:00', 'TimeZone', 'Asia/Tokyo');
You could create a function as follows to compare the values in a common timezone, here we use UTC:
 
function isSameHrMin = SameHourMinute(dtimes, query)
    dtimes.TimeZone = 'UTC';
    query.TimeZone = 'UTC';
    isSameHrMin = timeofday(dtimes) == timeofday(query);
end
This function will return the indices of datetime values with the same timezone dependent hour, minute and second values.