I'm using Rails 3.0.4, Ruby 1.9.2p0 on a Mac machine. While using Sqlite as the default database and successfully added respond_to :xml functionality, I see the datetime format in the xml is something like:
<updated-at type="datetime">2011-03-20T12:15:47Z</updated-at>
While there're several posts on the web (also here) asking how to change the date/time format like using configuration in config/locale/en.yml, or add
Time::DATE_FORMATS[:default] = "%Y-%m-%d %H:%M:%S"
in the initializer file, neither work.
I think the problem is because when I call someobj.to_xml, for the datetime objects, rails will call
datetime.xmlschema
instead of calling
datetime.to_s
which bypass the settings mentioned above. Although I know this may be the culprit, I don't know how to fix it. Anyone has experience on this? Thanks a lot!
If you absolutely need to change it you can override the xmlschema method instead of the to_s
class DateTime
def xmlschema
strftime("%Y-%m-%d %H:%M:%S")
end
end
But as I said in the comment you are breaking the XLM standard and application connecting to yours will not expect this datetime format.
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