So when the user inser the time,(otherwise the time is alreday set from the beginning as it's shown which is London for me)
how can I convert it into different countries time zone?
This is what i did and I got an error,
london= datetime(2019,02,28,0,0,0,'TimeZone','local','format','d - MMM - y HH:mm:ss Z')
for time =input('Choose: Amsterdam,Tokyo,Canberra,Los Angeles,New York,Local(London)')
if time == 'amsterdam' | 'Amsterdam'
ams= london +hours(1)
disp(ams)
elseif time == 'Tokyo' | 'tokyo'
tok= london + hours(9)
disp(tok)
elseif time == 'Canberra'|'canberra'
can = london +hours(11)
disp(can)
elseif time == 'Los Angeles'|'los angeles'
los= london + hours(-8)
disp(los)
elseif time == 'New York' |'new york'
new= london +hours(-5)
disp(new)
else
disp('Choose again')
end
end

댓글 수: 3

Walter Roberson
Walter Roberson 2019년 3월 3일
Ella Yeo comments
As this was a part of my project at school, I am concerned if anyone would use my answer on their projects too.
Walter Roberson
Walter Roberson 2019년 3월 3일
Ella,
The volunteers respond for the good of everyone, including other students who might have similar questions.
Public responses that everyone can read is the price that we "charge" for our volunteer services: people who do not want responses to become public should be hiring private consultants.
Image Analyst
Image Analyst 2019년 3월 3일
I've marked it as homework for you. Because it's homework, just as others can't copy your answer, you can't submit my answer as your own either, or you might get in trouble.

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2019년 2월 28일

0 개 추천

Why make them type it in? Just use menu():
london= datetime(2019,02,28,0,0,0,'TimeZone','local','format','d - MMM - y HH:mm:ss Z')
timeZones = {'Amsterdam', 'Tokyo', 'Canberra', 'Los Angeles', 'New York', 'Local (London)'}
button = menu('Choose your time zone', timeZones)
if button == 1
% Amsterdam
ams= london +hours(1)
disp(ams)
elseif button == 2
% Tokyo
tok= london + hours(9)
disp(tok)
elseif button == 3
% Canberra
can = london +hours(11)
disp(can)
elseif button == 4
% Los Angeles
los= london + hours(-8)
disp(los)
elseif button == 5
% New York
new = london + hours(-5)
disp(new)
else
% London
disp('No time difference from London to London')
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 2월 28일
편집: Walter Roberson 2019년 2월 28일

0 개 추천

if strcmpi(time, 'Amsterdam') %case insensitive comparisons
ams = ...
disp(ams)
elseif strcmpi(time, 'Tokyo')
tok = ...
disp(tok)
elseif ....
end
or
if ismember(time, {'amsterdam', 'Amsterdam'})
ams = ...
disp(ams)
elseif ismember(time, {'tokyo', 'Tokyo'})
tok = ...
disp(tok)
elseif ...
end

카테고리

도움말 센터File Exchange에서 Write Data to Channel에 대해 자세히 알아보기

질문:

2019년 2월 28일

댓글:

2019년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by