Unix Timestamp in Ruby

Use the standard library `Time` class. ActiveSupport (Rails) adds nice helpers like `1.day.ago` if you need them.

Common Operations

Get current Unix timestamp

ts = Time.now.to_i
# 1706745600

Convert Unix timestamp to Time

t = Time.at(1706745600)
# 2024-01-31 22:40:00 +0000

Convert Time to Unix timestamp

ts = Time.parse('2024-01-31T22:40:00Z').to_i
# 1706740800

Format as ISO 8601

Time.now.utc.iso8601
# '2024-01-31T22:40:00Z'

Parse ISO 8601

require 'time'
t = Time.iso8601('2024-01-31T12:00:00Z')
# 2024-01-31 12:00:00 UTC

Other Languages

Need the full converter? Open the Timestamp Converter →