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

WebKit/Chrome Timestamp convert into 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 Timestamp Converter

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

谢谢。

来自 this question

Google timestamp is formatted as the number of microseconds since January, 1601

这里有一个 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'