Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get DateTime.parse to return a time in your time zone?

Tags:

date

ruby

I need this

 require 'date'
 DateTime.parse "Mon, Dec 27 6:30pm"

to return a DateTime for 6:30pm in the EDT timezone, but it returns one in UTC. How can I get a EST DateTime or convert the UTC one into an EDT DateTime with a 6:30pm value?

like image 281
dan Avatar asked Jan 02 '11 02:01

dan


1 Answers

OK I'm going to offer an answer to my own question

require 'time'
ENV["TZ"] = "US/Eastern"
Time.parse("Mon, Dec 27 6:30pm").to_datetime
=> #<DateTime: 2011-12-27T18:30:00-05:00 (117884327/48,-5/24,2299161)> 
like image 159
dan Avatar answered Oct 05 '22 16:10

dan