date and time format change

i have a cell n x 2 table array. The first column containd dateas in the format of
'yyyy-MM-dd''T''HH:mm:ss.SSSSSSSSS''Z'''
I wish to change this to the following format
20130501000000, = 'YYYMMDD000000', which is '%Y%m%d%H%M%S'
I will then want to change the table array to a text file
I was hoping to use something like this to change the format. Any guidance would help.
New_datetime_new = datetime(EUR_USD.Date,'inputformat','yyyy-MM-dd''T''HH:mm:ss.SSSSSSSSS''Z''');

3 comentarios

Stephen23
Stephen23 el 1 de Mayo de 2019
@ Charles: please upload the cell array in a .mat file by clicking the paperclip button.
Charles
Charles el 1 de Mayo de 2019
See .matf ile attached. i wish to change the date format to that in the .txt file. I wish to retain the close price column and in fact make two colums of closing price and rhenc onvert this to the .txt file
dpb
dpb el 1 de Mayo de 2019
What is the time zone???
You don't separate the Z timezone code as a literal as do the 'T'.

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 1 de Mayo de 2019
Editada: dpb el 1 de Mayo de 2019

1 voto

>> tst=GBP_USD.Date(1:10); % just a sample set to play with
>> datetime(tst,'InputFormat','yyyy-MM-dd''T''HH:mm:ss.SSSSSSSSSZ', ...
'TimeZone','Europe/London','Format','yyyyMMddHHmmss')
ans =
10×1 datetime array
20190501095950
20190501095955
20190501100000
20190501100005
20190501100010
20190501100015
20190501100020
20190501100025
20190501100030
20190501100035
>>

6 comentarios

dpb
dpb el 1 de Mayo de 2019
[Charles Answer moved to Comment..dpb]
Looks good. Will try this. I feel the time is correct as written. I will check. Thank you. Presumably i can append thie to the prices column and save as q text file? I will try. Thanks
dpb
dpb el 1 de Mayo de 2019
Depends on just what you want in the text file and in what format...if you just need for export/import and not fancy formatting for visual presentation, then putting into a table and writetable is probably the simplest thing to do...but it produces a "barebones" csv text file, not particularly pretty.
Peter Perkins
Peter Perkins el 3 de Mayo de 2019
This
'TimeZone','Europe/London'
might be problematic -- London time is Zulu only half the year (and not currently). If all the timestamps have a trailing Z, there are two options:
1) '...SSSSSSSSSZ' in dpb's answer is the "correct" way to read them, and since you are reading a timezone, datetime requires that you specify a timezone for the result. It might be 'Europe/London', but it might also be 'UTC'.
2) Treat the Z as a literal, in both input and output, in other words, create an "unzoned" datetime array. But all of the timestamps better have a Z.
dpb
dpb el 3 de Mayo de 2019
2) Hmmm, Peter, I thought I had tried that and datetime barfed...have to go back and see if can find that in command history to see if I had a syntax error maybe...
1) I just chose London for lack of anything other info...
Charles
Charles el 4 de Mayo de 2019
Hi Guys...yes the time i in fact use is UTC, but adjusted for UK time I believe.
Peter Perkins
Peter Perkins el 9 de Mayo de 2019
Then it seems like dpb had the right answer. Reputation heading for 10K!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2018a

Etiquetas

Preguntada:

el 1 de Mayo de 2019

Comentada:

el 9 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by