フィルターのクリア

How to convert 64 bit integer timestamp to yyyymmddHHMMSSffffff format?

44 ビュー (過去 30 日間)
Sourav Mondal
Sourav Mondal 2020 年 9 月 11 日
コメント済み: Sourav Mondal 2020 年 9 月 11 日
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
Sourav Mondal
Sourav Mondal 2020 年 9 月 11 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by