如何使用 Ruby 解析以 little-endian 格式给出的 64 位整数时间戳?

How to parse timestamps given as 64-bit integer in little-endian format with Ruby?

我很好奇如何在 Ruby 中解析这些奇怪的时间戳:

566455139129676
566455199011666
566455199892825
566455259010949
566455319010859
566455335000847
566455336000936
566455336127533
566455347898055

以下是我对这些时间戳格式的了解:

The value is a 64-bit integer in little-endian format containing the number of microseconds since Julian day: Jan 01 2000 00:00:00 in the UTC timezone.

出于好奇,这些是 Vertica 对时间戳的内部表示:https://my.vertica.com/docs/9.0.x/HTML/index.htm#Authoring/AdministratorsGuide/BinaryFilesAppendix/ColumnDefinitions.htm

如有任何帮助,我们将不胜感激。

不太确定字节序与这里的任何内容有什么关系。你已经有一个整数了。

所以 Epoch 是 2000 年 1 月 1 日?基本上你只需要考虑 1969-12-31 和他们的时代之间的差异...

epoch = Time.new(2000, 1, 1)

epochOffset = epoch.to_i - Time.at(0).to_i;

ts = Time.at((566455347898055 / 1000000) + epochOffset)

print ts.strftime "%Y-%m-%d %H:%M:%S %z";

> 2017-12-13 04:42:27 +0000