How to convert 64 bit integer timestamp to yyyymmddHHMMSSffffff format?

45 visualizaciones (últimos 30 días)
Hi
I have a timeseries data whose each record has a timestamp in microseconds and are recorded in 64 bit integer format. Data starts from May 1,2011, Sunday, 19:00 EDT. However, I want create a histogram of the interarrival times. Therefore, I want to first convert the timestamps into yyyymmddHHMMSSffffff format and then store it as an integer/double.
A few sample values are: 3679705205, 4998039591, 5638258864, 10464755368, and so on. Therefore, I shall be really thankful if someone can help write a small piece of code to solve this issue.
Thanks,
Sourav
  2 comentarios
Cris LaPierre
Cris LaPierre el 11 de Sept. de 2020
Help us out by sharing what the datetime equivalent of 3679705205, 4998039591, 5638258864, and 10464755368 are.
Sourav Mondal
Sourav Mondal el 11 de Sept. de 2020
I don't know exactly. All I know is that the data starts from May 1, 2011, Sunday, 19:00 EDT.

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 11 de Sept. de 2020
My best guess would be to use datetime and set the 'Epoch' and 'TicksPerSecond' name-value pairs. Perhaps something like this?
t = [3679705205; 4998039591; 5638258864; 10464755368];
d = datetime(t,'ConvertFrom','epochtime','Epoch',datetime(2011,5,1,19,0,0),'TicksPerSecond',1e6)
d =
4×1 datetime array
01-May-2011 20:01:19
01-May-2011 20:23:18
01-May-2011 20:33:58
01-May-2011 21:54:24
  4 comentarios
Steven Lord
Steven Lord el 11 de Sept. de 2020
No. There's no integer type in MATLAB large enough to store those exactly and it is greater than flintmax. If you try to make it a uint64 it saturates at intmax.
>> uint64(20110501200119705205)
ans =
uint64
18446744073709551615
But if you want to create a histogram you can do that with the original datetime array. There's no need to convert to a numeric array.
t = [3679705205; 4998039591; 5638258864; 10464755368];
d = datetime(t,'ConvertFrom','epochtime',...
'Epoch',datetime(2011,5,1,19,0,0),...
'TicksPerSecond',1e6,...
'Format','yyyyMMddHHmmssSSSSSS');
histogram(d)
Or if you want the histogram of the difference between those times:
histogram(diff(d), 'BinWidth', minutes(5)) % 5 minute wide bins

Iniciar sesión para comentar.

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