The above solutions share a problem

E

elisabeth.mangler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,592
Members
45,104
Latest member
LesliVqm09
Top