代码之家  ›  专栏  ›  技术社区  ›  twneale

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

  •  3
  • twneale  · 技术社区  · 7 年前

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

    566455139129676
    566455199011666
    566455199892825
    566455259010949
    566455319010859
    566455335000847
    566455336000936
    566455336127533
    566455347898055
    

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

    该值是一个64位整数,采用little-endian格式,包含 朱利安日后的微秒数:2000年1月1日00:00:00 UTC时区。

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

    任何帮助都将不胜感激。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Max    7 年前

    我真的不知道endianness和这里有什么关系。你已经有一个整数了。

    那么纪元是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