Lance Pollard
Lance Pollard

Reputation: 79268

Ruby time in 2009-02-17T05:00-07:00 format?

How do I print out a ruby time using the date-time format:

2009-02-17T05:00-07:00

Like Time.now.to_datetime_s

Upvotes: 0

Views: 244

Answers (3)

Greg Campbell
Greg Campbell

Reputation: 15302

Time#iso8601 (or Time#xmlschema) produces output in this format. (You may have to require 'time' beforehand).

Upvotes: 5

ceth
ceth

Reputation: 45295

Time.new.strftime(<format string>)

Upvotes: 0

Daniel Abrahamsson
Daniel Abrahamsson

Reputation: 1965

Have you checked out Time#strftime? You can read more about it at: http://ruby-doc.org/core/classes/Time.html#M000298.

Upvotes: 1

Related Questions