donovan.lampa
donovan.lampa

Reputation: 684

Ruby: Transform a string of time to xsd:datetime conforming string?

I have this: "2013-02-23 18:06:00 UTC"

and need this: "2013-02-23T18:06:00Z"

to conform to this: http://books.xmlschemata.org/relaxng/ch19-77049.html

Does anyone know of a good library/tool/method in Ruby to do this without having to write some transformation method?

Upvotes: 1

Views: 1254

Answers (2)

Jay Shepherd
Jay Shepherd

Reputation: 2046

Within Rails:

DateTime.now.utc.strftime()
=> "2012-08-22T17:55:12+00:00" 

Upvotes: 2

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9691

Check out the rubydocs for Datetime here. There's a method to convert into ISO8601.

Upvotes: 2

Related Questions