Convert Datetime with arbitrary time zone to a corresonding Time object, keeping the zone, in ruby 1.8.6

74 views Asked by At

I'm using ruby 1.8.6 on an old server.

I have a DateTime object which is created like this:

dt = DateTime.new(2021, 8, 25, 3, 30, 0).change(:offset => "+0200")
=> Wed, 25 Aug 2021 03:30:00 +0200

That's fine as is. However, I want it to be a Time object instead of a DateTime and I can't figure out how. If I call ".to_time" it just stays as a DateTime object. I can do this:

>> Time.parse(dt.to_s)
=> Wed Aug 25 02:30:00 +0100 2021

and that is showing the time in my local time zone, but I want it to be shown in the +0200 timezone, with that zone stored in the Time object.

Is this possible?

0

There are 0 answers