Azzera filtri
Azzera filtri

Number to datetime from textdata

1 visualizzazione (ultimi 30 giorni)
Mikkel Ibsen
Mikkel Ibsen il 15 Mar 2018
Modificato: dpb il 15 Mar 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 Commento
Greg
Greg il 15 Mar 2018
Modificato: Greg il 15 Mar 2018
Help us first - what have you tried? Post the relevant code.

Accedi per commentare.

Risposta accettata

dpb
dpb il 15 Mar 2018
Modificato: dpb il 15 Mar 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
>>

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by