For Developers

Unix Timestamp in Ruby

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in Ruby — plus the specific mistake that trips up Ruby code more than any other.

Time.now.to_i
Time.at(1750000000).utc
Time.parse("2025-06-15 12:00:00 UTC").to_i

The Ruby-specific pitfall

Time.now returns a time in the system's local zone, not UTC, and calling .to_i on it still gives the correct Unix timestamp (Unix time is zone-independent by definition) — but any formatting you do before converting will silently reflect local time. Call .utc explicitly whenever you need to guarantee what timezone a formatted string represents.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading