Number to datetime from textdata

2 visualizaciones (últimos 30 días)
Mikkel Ibsen
Mikkel Ibsen el 15 de Mzo. de 2018
Editada: dpb el 15 de Mzo. de 2018
Hi
I have this data that comes in a text document like this:
"%20180313123648396"
"%20180313123656586"
"%20180313123657351"
"%20180313123658552"
"%20180313123659316"
I need a way for matlab to read the numbers and then make it into a datetime.
So they would come out like:
13-03-2018 12:36:48
13-03-2018 12:36:57
13-03-2018 12:36:57
13-03-2018 12:36:59
13-03-2018 12:36:59
How do I do that? I know how to remove the % sign, but i cant make a number into a datetime, I've tried to sat the InputFormat to: yyyyMMDDHHMMSS but it cannot read it.
Please help
  1 comentario
Greg
Greg el 15 de Mzo. de 2018
Editada: Greg el 15 de Mzo. de 2018
Help us first - what have you tried? Post the relevant code.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 15 de Mzo. de 2018
Editada: dpb el 15 de Mzo. de 2018
If I put your exact text in a file then
>> fmt='%{%yyyyMMddHHmmssSSS}D'
fmt =
%{%yyyyMMddHHmmssSSS}D
>> fid=fopen('mikkel.dat');
>> d=textscan(fid,fmt,'collectoutput',1)
d =
cell
[5×1 datetime]
>> fid=fclose(fid);
>> d=d{:}
d =
5×1 datetime array
%20180313123648396
%20180313123656586
%20180313123657351
%20180313123658552
%20180313123659316
>> d.Format='default'
d =
5×1 datetime array
13-Mar-2018 12:36:48
13-Mar-2018 12:36:56
13-Mar-2018 12:36:57
13-Mar-2018 12:36:58
13-Mar-2018 12:36:59
>>

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by