tags:

views:

224

answers:

2

I have Fri Jun 26 23:05:00 -0400 2009 Which I'd like to convert into Eastern (US) time. How can this be done with Ruby?

Thanks

A: 

http://tzinfo.rubyforge.org/doc/files/README.html

Part of activesupport

Omar Qureshi
+2  A: 
require 'tzinfo'

input_time = Time.parse('Fri Jun 26 23:05:00 -0400 2009')
input_time.utc
puts "input_time = #{input_time}"

est_tz = TZInfo::Timezone.get('EST')

time_in_est = est_tz.utc_to_local(input_time)

puts "time_in_est = #{time_in_est}"

What we're doing here is:

  • parse the given date string
  • convert it to UTC
  • use the tzinfo gem to lookup timezone info for 'EST' (which I'm assuming is what you meant by 'Eastern (US) time')
  • convert the utc input time into a local time for the EST timezone
Pete Hodgson
love it, thanks for the step by step!