필터 지우기
필터 지우기

How to convert 64 bit integer timestamp to yyyymmddHHMMSSffffff format?

조회 수: 44 (최근 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에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by