Formatting Dates January 17th, 2008

Wrong:

<% time = Time.now %>
<%= Date.today.to_s.gsub('-','/') %> <%= "#{time.hour > 12 ? time.hour - 12 : time.hour}:#{time.min}" %>

Right:

<%= Time.now.strftime('%m/%d/%Y %I:%M') %>

Please learn and love Time#strftime

Sorry, comments are closed for this article.