How to Get Unix Time in Ruby

Posted on
  • get current unix time

    • float
      since_epoch_float = Time.new.utc.to_f
      
    • integer
    • since_epoch_int = Time.new.utc.to_i
      
  • get unix time corresponding to a specific date

    my_datetime = Time.utc(1979, 3, 7, 21, 0, 0)
    since_epoch_int = my_datetime.to_i
    
  • get time object corresponding to a specific unix time

    my_datetime = Time.at(289688400).utc
    

 

Leave a Reply

Your email address will not be published. All fields are required.