Import datetime with MESZ format

3 visualizaciones (últimos 30 días)
Tamara Szecsey
Tamara Szecsey el 20 de Dic. de 2021
Comentada: Cris LaPierre el 22 de Dic. de 2021
Hi,
I want to import an csv file with the following datetime format:
24.Sep 2021 14:09:00 MESZ
I had another csv with a different datetime format, where I used
Size_Datum_in_char = size(Datum_in_char,1);
Datum_full = [];
for i = 1:Size_Datum_in_char
T = datetime(Datum_in_char(i,1),'TimeZone','local','InputFormat','yyyy-MM-dd''T''HH:mm:ssX');
Datum_full = [Datum_full; T];
end
Where Datum_in_char is the imported matrix of the csv's first row with the datetime stored as char.
Now I tried:
T = datetime(Datum_in_char(i,1),'TimeZone','local','InputFormat','dd.MM yyyy hh:mm:ss XXXX');
but It seams, that I cannot import the "MESZ" with Xes. Any ideas, what I could do?
Thank you.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 20 de Dic. de 2021
Editada: Cris LaPierre el 21 de Dic. de 2021
I don't believe MATLAB is able to automatically recognize the timezone code. Importing might be a two step process where the dates are first read in as strings, then the codes are replaced with UTC offsets, which then allows the data to be converted to datetimes.
d='24.Sep 2021 14:09:00 MESZ';
dd = replace(d,'MESZ','+02:00');
D = datetime(dd,'InputFormat','dd.MMM yyyy HH:mm:ss xxxxx','TimeZone','UTC')
See the datetime documentation page to learn more about the Format and TimeZone properties.
  6 comentarios
Tamara Szecsey
Tamara Szecsey el 22 de Dic. de 2021
Oh, that's weird, because the csv was generated from other sensors. Good to know though.
So you would recomment to import this as a table? I imported the data I need as two matrices.
This is helping me a lot, thank you.
Cris LaPierre
Cris LaPierre el 22 de Dic. de 2021
Ultimately it depends on what you need to do, but my default approach is to create tables. If they are new to you, the most helpful page for me was How to Access Data in Tables.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by