필터 지우기
필터 지우기

Datetime format capatilization sensitivity inconsistent?

조회 수: 2 (최근 30일)
Samuel Cheung
Samuel Cheung 2024년 7월 26일
댓글: Samuel Cheung 2024년 7월 26일
So I was trying to add milliseconds to my datetime variables and found a sort of inconsistency?
When setting datetime format using datetime('now','Format','hh:mm:ss.sss') , the sss at the end is not capatilization sensitive; but when trying to access and change it using variable_name.Format = 'hh:mm:ss.SSS', the SSS at the end is capatilization sensitive.
Is this a minor inconsitency or is this intended? If it's the latter what is the rationale behind? As it only makes it more confusing imo
  댓글 수: 1
Samuel Cheung
Samuel Cheung 2024년 7월 26일
Hi Himanshu,
I am using 2022a. variable_name.Format = 'hh:mm:ss.sss' is not valid and would yield an error. The issue has now been resolved by the staff below and they provided a good explanation of what sss is doing so you could take a look if you are interested.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 7월 26일
It is case-sensitive in both contexts. Either way, you get a result with 3 decimal places, but notice that the result is just a repeat of the seconds if you use 'sss'.
T1 = datetime('now','Format','hh:mm:ss.sss')
T1 = datetime
02:21:38.038
T1 = datetime('now','Format','hh:mm:ss.SSS')
T1 = datetime
02:21:38.975
This is also true when using variable_name.Format = 'hh:mm:ss.SSS'
T2 = datetime('now');
T2.Format = 'hh:mm:ss.sss'
T2 = datetime
02:21:38.038
T2.Format = 'hh:mm:ss.SSS'
T2 = datetime
02:21:38.984
In short, you must use 'SSS' if you want to include milliseconds
  댓글 수: 1
Samuel Cheung
Samuel Cheung 2024년 7월 26일
Ah, thank you. Didn't realise it's repeating the seconds with sss.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Stability Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by