Azzera filtri
Azzera filtri

How to convert 64 bit integer timestamp to yyyymmddHHMMSSffffff format?

44 visualizzazioni (ultimi 30 giorni)
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 Commenti
Cris LaPierre
Cris LaPierre il 11 Set 2020
Help us out by sharing what the datetime equivalent of 3679705205, 4998039591, 5638258864, and 10464755368 are.
Sourav Mondal
Sourav Mondal il 11 Set 2020
I don't know exactly. All I know is that the data starts from May 1, 2011, Sunday, 19:00 EDT.

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 11 Set 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 Commenti
Steven Lord
Steven Lord il 11 Set 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB 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