WebKit/Chrome Timestamp convert into Ruby/Rails

Viewed 519
1 Answers

From this question

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

So here an Ruby example :

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'
Related