Forum: Ruby The above solutions share a problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8e4379daaaa55dff845a0f4ea6fa359a?d=identicon&s=25 unknown (Guest)
on 2005-12-27 05:04
(Received via mailing list)
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 :-)

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
This topic is locked and can not be replied to.