Reading dates/times from a text file

조회 수: 12 (최근 30일)
dormant
dormant 2021년 8월 24일
댓글: Star Strider 2021년 8월 25일
I want to read all the dates and times from a text file into an array of serial date numbers.
I've always done this in the past with textread and then parsing the date string.
There seems to be a more elegant way to do this, using readtable, but I'm struggling to make it work.
The format of the lines in the text file is this:
20210824_UTC_06:47:41
How do I read these in, using readtable or some other way?

답변 (1개)

Star Strider
Star Strider 2021년 8월 24일
That is not a straightforward as it would fitst appear.
Try this —
Time = '20210824_UTC_06:47:41'
Time = '20210824_UTC_06:47:41'
DT = datetime(Time, 'InputFormat','yyyyMMdd''_UTC_''HH:mm:ss', 'TimeZone','UTC')
DT = datetime
24-Aug-2021 06:47:41
DT.TimeZone = '-7' % Convert To: UTC-7:00:00
DT = datetime
23-Aug-2021 23:47:41
.
  댓글 수: 2
dormant
dormant 2021년 8월 25일
Thank you.
Star Strider
Star Strider 2021년 8월 25일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by