converting Date object to TimeWithZone

Posted by avaynshtok on Stack Overflow See other posts from Stack Overflow or by avaynshtok
Published on 2010-03-25T18:42:23Z Indexed on 2010/03/25 18:43 UTC
Read the original article Hit count: 363

Filed under:
|
|

I need to convert a Date object into a TimeWithZone object representing the beginning of that day in a given time zone.

The following approach works, but seems too convoluted as it requires me to convert the date to a string:

?> date = Date.parse("2010-02-17")
=> Wed, 17 Feb 2010
>> ActiveSupport::TimeZone['Eastern Time (US & Canada)'].parse(date.to_s)
=> Wed, 17 Feb 2010 00:00:00 EST -05:00
>> ActiveSupport::TimeZone['UTC'].parse(date.to_s)
=> Wed, 17 Feb 2010 00:00:00 UTC 00:00

Is there a better way I'm missing?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activesupport