Formatting a date with or without the time


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def format_date(date, use_time = false)
  2. if use_time == true
  3. ampm = date.strftime("%p").downcase
  4. new_date = date.strftime("%B %d, %Y at %I:%M" + ampm)
  5. else
  6. new_date = date.strftime("%B %d, %Y")
  7. end
  8. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.