how to use datetime for special time format?

2 visualizaciones (últimos 30 días)
pooria mazaheri
pooria mazaheri el 12 de Abr. de 2019
Comentada: pooria mazaheri el 19 de Abr. de 2019
hi guys
i have this kind of time format:
but "datetime" function does not work.
would u help me? thanks in advance.
  1 comentario
Brian Hart
Brian Hart el 12 de Abr. de 2019
Can you post the command that doesn't work, with the error message? Did you try specifying the InputFormat setting?

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 13 de Abr. de 2019
It is not possible to create a single datetime() call that will handle all three of those lines. You need to separate out the lines with the two different formats. The InputFormat to use for the 312 line is 'yyyy-MM-dd HH:mm:ss.SSSSSS' . For the 311 and 313 line, the format would be the same without the '.SSSSSS'
  2 comentarios
Peter Perkins
Peter Perkins el 16 de Abr. de 2019
Walter's right; the4 usual thing to do would be to use 'yyyy-MM-dd HH:mm:ss to convert "most" of them, then go back and use 'yyyy-MM-dd HH:mm:ss.SSSSSS' to convert the rest. You can find the ones that didn't convert using isnat.
>> s = ["2019-04-16 11:56:14" "2019-04-16 11:56:15.123" "2019-04-16 11:56:16"]
s =
1×3 string array
"2019-04-16 11:56:14" "2019-04-16 11:56:15.123" "2019-04-16 11:56:16"
>> d = datetime(s,'Format','dd-MMM-yyyy HH:mm:ss.SSS')
d =
1×3 datetime array
16-Apr-2019 11:56:14.000 NaT 16-Apr-2019 11:56:16.000
>> d(isnat(d)) = datetime(s(isnat(d)),'InputFormat','yyyy-MM-dd HH:mm:ss.SSS')
d =
1×3 datetime array
16-Apr-2019 11:56:14.000 16-Apr-2019 11:56:15.123 16-Apr-2019 11:56:16.000
pooria mazaheri
pooria mazaheri el 19 de Abr. de 2019
thank you all

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by