How to convert 64 bit integer timestamp to yyyymmddHHMMSSffffff format?

39 次查看(过去 30 天)
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 个评论
Cris LaPierre
Cris LaPierre 2020-9-11
Help us out by sharing what the datetime equivalent of 3679705205, 4998039591, 5638258864, and 10464755368 are.
Sourav Mondal
Sourav Mondal 2020-9-11
I don't know exactly. All I know is that the data starts from May 1, 2011, Sunday, 19:00 EDT.

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2020-9-11
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 个评论
Steven Lord
Steven Lord 2020-9-11
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by