snippetrubyCritical
How to convert a unix timestamp (seconds since epoch) to Ruby DateTime?
Viewed 0 times
howdatetimetimestampsincerubyconvertepochsecondsunix
Problem
How do you convert a Unix timestamp (seconds since epoch) to Ruby DateTime?
Solution
DateTime.strptime can handle seconds since epoch. The number must be converted to a string:require 'date'
DateTime.strptime("1318996912",'%s')Code Snippets
require 'date'
DateTime.strptime("1318996912",'%s')Context
Stack Overflow Q#7816365, score: 400
Revisions (0)
No revisions yet.