Borrar filtros
Borrar filtros

Datetime format capatilization sensitivity inconsistent?

3 visualizaciones (últimos 30 días)
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 comentario
Samuel Cheung
Samuel Cheung el 26 de Jul. de 2024
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.

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 26 de Jul. de 2024
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

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by