mr_muscle
mr_muscle

Reputation: 2900

Ruby float to date time

I've got response from Sidekiq::Worker where created_at is a float

active_workers.map { |w| w.dig('created_at') }.first => 1653562493.6044002

How to change that value to date time? I've tried to do simple .to_date but it return me an error:

NoMethodError: undefined method `to_date' for 1653562493.6044002:Float

Upvotes: 0

Views: 314

Answers (1)

Manoj Saun
Manoj Saun

Reputation: 36

Just adding the answer mentioned in the comment by Stefan

Time.at(1653562493.6044002)

Also, if Timezone is a crucial factor we can use the below code as well

Time.zone.at(1653562493.6044002)

Upvotes: 1

Related Questions