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

问题描述 投票:3回答:1

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

566455139129676
566455199011666
566455199892825
566455259010949
566455319010859
566455335000847
566455336000936
566455336127533
566455347898055

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

该值是一个64位整数,采用little-endian格式,包含自Julian日以来的微秒数:UTC时区的01 01 00 00:00:00。

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

非常感激任何的帮助。

ruby timestamp vertica
1个回答
3
投票

不确定这里有什么字节序有什么关系。你已经有了一个整数。

那么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
© www.soinside.com 2019 - 2024. All rights reserved.