Home > OS >  Ruby float to date time
Ruby float to date time

Time:05-31

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

CodePudding user response:

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)
  • Related