Datetime format capatilization sensitivity inconsistent?

22 次查看(过去 30 天)
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,14:42
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,14:22
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

更多回答(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