I have a data set with timestamps:
'11/5/2019 12 a.m. EST'
...
'11/10/2019 1 p.m. EST'
How can I convert these timestamps into a vector of date numbers?
thanks for the help.

댓글 수: 4

Adam Danz
Adam Danz 2019년 11월 15일
편집: Adam Danz 2019년 11월 15일
Examples are needed. "timestamps" is a vague term. Are those datetime values? Are they date strings? What is continuous date numbers?
Walter Roberson
Walter Roberson 2019년 11월 15일
Are the periods part of the text? Is it possible for the time zone to be anything other than EST (for example can it be EDT? Can it be GMT? PDT?)
Brenton Hirao
Brenton Hirao 2019년 11월 15일
Walter Robinson, the periods are part of the text. The data only contains EST.
Adam Danz
Adam Danz 2019년 11월 15일
So you're converting from strings to datenum?
https://www.mathworks.com/help/matlab/ref/datenum.html
It might be necessary to remove the dots first using strrep but maybe not (my machine has been shut down for the night).

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

 채택된 답변

Shubham Gupta
Shubham Gupta 2019년 11월 15일

1 개 추천

Assuming there is ".m. EST" attached to each "timestamp" at the end. You can follow the steps:
Step-1 Replace ".m. EST" to just "m" (Hint : regexprep)
Step-2 Convert the output into the date numbers (Hint: datenum)
You should get the output with date numbers in a array. (Not sure what do mean by "continuous"?)

댓글 수: 2

S = '11/5/2019 12 a.m. EST';
temp = regexprep(S, '\.m\.', 'm');
t = datetime(temp, 'Inputformat', 'd/M/yyyy h a z', 'TimeZone', 'America/Chicago');
The above will have "eastern time" as the attached timezone. You can switch it to EST but you will get a warning,
Warning: 'EST' specifies a time zone with a fixed offset from UTC, -05:00. This zone does not follow daylight saving time, and so may give unexpected results. See the datetime.TimeZone property for details about specifying time zones.
Instead of the regexprep() you could also do
temp = strrep(S,'.','');

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

질문:

2019년 11월 15일

댓글:

2019년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by