필터 지우기
필터 지우기

How to read dates/times with time zone

조회 수: 15 (최근 30일)
Robert
Robert 2018년 4월 17일
댓글: Robert 2018년 4월 18일
Hi,
Wondering how to read the following dates/times:
2003-01-16T06:28:00Z
2003-02-16T03:13:00Z
2003-03-16T04:11:07Z
...
Then create 6 columns with that info like:
YYYY mm dd HH MM SS
2003 01 16 06 28 00
2003 02 16 03 13 00
2003 03 16 04 11 07
...
Thank you for your help!
  댓글 수: 1
Robert
Robert 2018년 4월 17일
Sorry, I forgot to add my example...
t = datetime('2003-01-16T06:28:00Z','TimeZone','local','Format','yyyy-MM-dd''T''HH:mm:ss Z')

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

채택된 답변

Robert U
Robert U 2018년 4월 18일
편집: Robert U 2018년 4월 18일

Hello Robert:

I assume the original date is given in ISO8601 format. In that case 'Z' means zero offset to UTC+0.

Nevertheless, here is the code to read and convert as you requested:

 t = datetime('2003-01-16T06:28:00Z','TimeZone','local','InputFormat','yyyy-MM-dd''T''HH:mm:ssX');
 tOut = char( datetime(t,'Format','yyyy/MM/DD/HH/mm/ss') );
 cOut = strsplit(tOut,'/');
 strOut = sprintf('YYYY mm dd HH MM SS\n');
 strOut = [strOut,sprintf('%4s %2s %2s %2s %2s %2s\n',cOut{1},cOut{2},cOut{3},cOut{4},cOut{5},cOut{6})];
 disp(strOut)

Kind regards,

Robert

  댓글 수: 2
Robert U
Robert U 2018년 4월 18일
Or even shorter:
t = datetime('2003-01-16T06:28:00Z','TimeZone','local','InputFormat','yyyy-MM-dd''T''HH:mm:ssX');
tOut = char( datetime(t,'Format','yyyy MM DD HH mm ss') );
strOut = sprintf('YYYY mm dd HH MM SS\n');
strOut = [strOut,tOut];
disp(strOut)
Robert
Robert 2018년 4월 18일
Great, thank you so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by