---
title: Date and Time Formats for Pirates
teaser:
tags: web,rails
author: Alex Berry
published_on: 2012-04-27
---

Need to display a date in your Rails app? First try:

    Time.now.strftime "arrrround %H'ish"

To remove duplication, you imagine a [time format initializer](https://thoughtbot.com/blog/post/9012426894/custom-formats-for-datetime). Second try:

    Time.now.to_s :pirate

Then you remember the `:default` [localized](http://guides.rubyonrails.org/i18n.html#adding-date-time-formats) key. Third time's a charm:

    l Time.now

It formats based on the `config/locales/en.yml` file:

    en:
      time:
        formats:
          default: "arrrround %H'ish"
      date:
        formats:
          default: "arrrround %H'ish"

Dates work, too:

    l Date.today

[The same system](https://thoughtbot.com/blog/post/392707640/the-more-you-know-custom-time-descriptions) lets you alter the display of "days ago" and "minute from now."
