The above solutions share a problem


#1

Example:

require ‘date’
require ‘time’
dt = DateTime.parse(‘2005-12-24T12:00:00Z’) # UTC
lt = Time.parse(dt.strftime("%c"))
puts dt.asctime << " " << dt.zone
puts lt.asctime << " " << lt.zone

Output:

Sat Dec 24 12:00:00 2005 Z
Sat Dec 24 12:00:00 2005 CET

Timezone data is lost ("%c" does not include it nor do the other
examples - at least the ones I saw :slight_smile:

A solution that works very similar but with time zone included (%Z) und
thus gives expected results:

class DateTime
def to_time
Time.parse(strftime("%a %b %d %H:%M:%S %Z %Y"))
end
end

regards

eTM