How to I convert this time format to datetime?

9 visualizaciones (últimos 30 días)
Martin
Martin el 28 de Mayo de 2021
Comentada: Walter Roberson el 10 de En. de 2023
I got this strange time format: my str ='Fri May 28 18:15:46 +0000 2021'.
I would be very happy if I could get it down to '28-May-2021 18:15:46'.
Tried messing with datetime(), but with no luck
Thank in advance

Respuesta aceptada

Steven Lord
Steven Lord el 28 de Mayo de 2021
str ='Fri May 28 18:15:46 +0000 2021'
str = 'Fri May 28 18:15:46 +0000 2021'
inputFormat = 'eee MMM d H:mm:ss xx yyyy'
inputFormat = 'eee MMM d H:mm:ss xx yyyy'
dt = datetime(str, 'InputFormat', inputFormat, 'TimeZone', 'UTC')
dt = datetime
28-May-2021 18:15:46
I used the information in the description of the Format property on the documentation page for the datetime function to generate inputFormat. Most of the identifiers were in the "All Date and Time Formats" table. I wasn't sure whether you wanted to use Z, xx, or xxxx. When I tried just using the InputFormat name-value pair input MATLAB threw an error that indicated I needed to specify a TimeZone as well.

Más respuestas (1)

Walter Roberson
Walter Roberson el 28 de Mayo de 2021
str ='Fri May 28 18:15:46 +0000 2021'
str = 'Fri May 28 18:15:46 +0000 2021'
datetime(str, 'inputformat', 'eee MMM dd HH:mm:ss Z yyyy','timezone','utc')
ans = datetime
28-May-2021 18:15:46
  2 comentarios
Tota
Tota el 10 de En. de 2023
i have millscond (gaze time stamp) but need convert to time hh:mm:ss
if can help
Walter Roberson
Walter Roberson el 10 de En. de 2023
GazeTimestamp = [1535.81; 169225; 1614.36; 1254.72]
GazeTimestamp = 4×1
1.0e+05 * 0.0154 1.6923 0.0161 0.0125
D = seconds(GazeTimestamp ./ 1000);
D.Format = 'hh:mm:ss'
D = 4×1 duration array
00:00:01 00:02:49 00:00:01 00:00:01

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by