Forum: Ruby The above solutions share a problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2005-12-27 06:04
(Received via mailing list)

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


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 :-)

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"))


This topic is locked and can not be replied to.