WebKit / Chrome时间戳转换为Ruby / Rails

如何将WebKit / Chrome时间戳转换为Ruby / Rails。

这是来自Chrome excel 13130755192116927的时间戳数据,但我如何使用Ruby / Rails转换为人类可读的格式。

我找到了一些例子,比如How to convert a unix timestamp (seconds since epoch) to Ruby DateTime? 但是这个数据长度是13,我的数据长度是17。

我是如何实现这一点的,就像这个WebKit / Chrome时间戳转换器一样 。

 GMT: Sunday, February 5, 2017 7:59:52 AM 

谢谢。

从这个问题

Google时间戳的格式为自1601年1月以来的微秒数

所以这是一个Ruby示例:

 require 'date' chrome_timestamp = 13130755192116927 # Get the January 1601 unixepoch since_epoch = DateTime.new(1601,1,1).to_time.to_i # Transfrom Chrome timestamp to seconds and add 1601 epoch final_epoch = (chrome_timestamp / 1000000) + since_epoch # Print DateTime date = DateTime.strptime(final_epoch.to_s, '%s') # without formating puts date => '2017-02-05T07:59:52+00:00' # with formating puts date.strftime('%A, %B %-d, %Y %-I:%M:%S %p') => 'Sunday, February 5, 2017 7:59:52 AM' 
Interesting Posts