How do you convert a Unix timestamp (seconds since epoch) to Ruby DateTime?
Ruby – How to convert a unix timestamp (seconds since epoch) to Ruby DateTime
datetimerubytimestamp
Related Topic
- C# – How to convert a Unix timestamp to DateTime and vice versa
- Mysql – Should I use the datetime or timestamp data type in MySQL
- Ruby – How to write a switch statement in Ruby
- Ruby – How to convert a string to lower or upper case in Ruby
- Python – Converting unix timestamp string to readable date
- Python – In Python, how do you convert seconds since epoch to a `datetime` object
- Python – How to convert a datetime object to milliseconds since epoch (unix time) in Python
- C# – How to get the unix timestamp in C#
Best Answer
Sorry, brief moment of synapse failure. Here's the real answer.
Brief example (this takes into account the current system timezone):
Further update (for UTC):
Recent Update: I benchmarked the top solutions in this thread while working on a HA service a week or two ago, and was surprised to find that
Time.at(..)
outperformsDateTime.strptime(..)
(update: added more benchmarks).