changing the time zone for two datetime objects then comparing them

22 ビュー (過去 30 日間)
MA
MA 2021 年 11 月 7 日
回答済み: Chris 2021 年 11 月 7 日
How can I modify the following lines so that, the datetime objects for the tables t and D are converted to 'Asia/Dubai' time zone then compared as desired. given that they are in 'UTC' timing.
I know how to change the timezone for datetime objects using .timezone, but although it might be quite simple, I don't seem to be able to do the comparison after that.
t= readtable('outputfile.txt');
%****************************************************************************
%reading the date and time
t.Date = datetime(t.YEAR, t.MONTH, t.DAY, t.HOUR, t.MIN, 0,'Format', 'uuuuMMddHHmm');
t.Date3 = datetime(t.YEAR, 0, t.DAY, t.HOUR, 0, 0,'Format', 'uuuuMMddHHmm');
%****************************************************************************************************************
D=readtable("DST.txt");
D.date = datetime(D.YEAR , 0, D.DOY ,D.HR,0, 0,'Format', 'uuuuMMddHHmm');
[Lia, Locb] = ismember(t.Date3, D.date);
indx = Locb(Locb > 0);
t.DST(Lia) = D.DST(indx);

回答 (2 件)

Star Strider
Star Strider 2021 年 11 月 7 日
See the datetime assiciated documentation section on Specify Time Zones.
.

Chris
Chris 2021 年 11 月 7 日
t.Date3.TimeZone = 'Asia/Dubai';
d.date.TimeZone = 'Asia/Dubai';
Works for me.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by