Making the string returned by Time.now look nicer

Newbie programmer here. I get this string when I call Time.now:

2012-03-18T23:40:44+01:00

How can I replace the T with a space and remove everything after 23:40
so that it looks like this?:

2012-03-18 23:40

Hi,

Vladimir Van B. wrote in post #1052207:

How can I replace the T with a space and remove everything after 23:40
so that it looks like this?:

2012-03-18 23:40

You shouldn’t. The to_s method is meant to show all data of the time
object (including the time zone, milliseconds etc.). If you want to get
a certain time format, use the strftime method:

http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime

now = Time.now
puts now.strftime(’%Y-%m-%d %H:%M’)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs