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

WebKit/Chrome Timestamp convert into Ruby/Rails

如何将webkit/chrome时间戳转换为ruby/rails。

这里是来自chromeExcel13130755192116927的时间戳数据,但我如何使用ruby/rails将其转换为可读格式。

我发现了一些例子,比如How to convert a unix timestamp (seconds since epoch) to Ruby DateTime?,但是这个数据长度是13&my data length是17。

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

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

谢谢。


从这个问题

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

这里有一个Ruby示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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'