How to subtract 'datetime' from 'datetime' in MATLAB GUI ?
Show older comments
Hi, I am designing a program to calculate the time different between two cities.
The operation is: subtracting second city time from the first one. I used the bellow code to get the cities time and convert it into 'string':
city1 = datestr(datetime('now','TimeZone','local',...
'Format','dd-MM-yyyy HH:mm:ss Z'));
city1.TimeZone = 'America/New_York';
city2 = datestr(datetime('now','TimeZone','local',...
'Format','dd-MM-yyyy HH:mm:ss Z'));
city2.TimeZone = 'Africa/Khartoum';
The output will be in a formatted string as:
city1 =
'25-Aug-2018 19:34:29'
city2 =
'25-Aug-2018 13:34:29'
The above is working properly but I can not subtract them in this form.
My question is: How to subtract the string forms above and get 4 cells output as "06:00" ?
1 Comment
The above cannot "work properly"...
>> c1=datestr(datetime('now','TimeZone','local','Format','dd-MM-yyyy HH:mm:ss Z'));
>> c1.TimeZone = 'America/New_York';
Field assignment to a non-structure array object.
>>
In fact, ML tries to address the variable as a struct but can't do that with a char string.
city1, city2 (I shortened to c1,c2) are char() arrays; you can't assign a property value to them.
OTOMH I'm not sure how to use the datetime object to display the time zone difference between two locations but I'm sure it's doable without manipulating the date strings...
Accepted Answer
More Answers (0)
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!