I have a DateTime object in Rails which outputs like this when called:
ruby-1.8.7-p302 > Time.now
=> Wed Nov 10 16:46:51 -0800 2010
How do I convert the DateObject to return an XML datetime type string like this:
ruby-1.8.7-p302 > Time.now.convert_to_xml
=> 2010-11-10T16:46:51-08:00
Time to XML format:
Time.now.xmlschema # implemented by Rails, not stock ruby
Time.now.strftime '%Y-%m-%dT%H:%M:%S%z'
http://corelib.rubyonrails.org/classes/Time.html#M000281
To parse (Ruby 1.9 and beyond):
t = Time.now.xmlschema(str)
http://ruby-doc.org/core-1.9/classes/Time.html#M000329
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With