Hello all.
I have a string array of times i'm trying to convert into datetime format.
the string array is as follows:
'12/24/2019 02:42:42:451 PM'
from it i take the parameters: year, month, day, hour (based on PM or AM), min, sec, msec.
and when trying to convert it into datetime using:
Ts = datetime(year,month,day,hour,min,sec,milli_sec,'InputFormat','yyyy-MM-dd HH:mm:ss.SSS');
I get:
datetime
24-Dec-2019 14:42:42
without the msec.
anyone knows why doesn't it take the msec into consideration?

댓글 수: 1

dpb
dpb 2019년 12월 29일
In
Ts = datetime(year,month,day,hour,min,sec,milli_sec,'InputFormat','yyyy-MM-dd HH:mm:ss.SSS');
you're mixing the input text format of the original with numeric arguments...I'd be surprised that works...
There's no reason to go to the trouble of parsing the string first; read it as is but then drop 'Input' from the named argument to set the display format.

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

 채택된 답변

Akira Agata
Akira Agata 2019년 12월 29일

3 개 추천

Please set the display format to show millisecond, like:
>> Ts.Format = 'uuuu/MM/dd HH:mm:ss.SSS';
>> Ts
Ts =
datetime
2019/12/24 14:42:42.451

댓글 수: 2

Orel Levy
Orel Levy 2019년 12월 29일
thanks, works perfect
Sreeraj T
Sreeraj T 2022년 5월 12일
Thanks a lot

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2019년 12월 29일

댓글:

2022년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by