This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Format dates with ease
version 1.0.0
license BSD3
native-modules False
Tag 1.0.0
Committed At 2015-03-01 12:27:57 UTC
elm-lang/core 1.0.0 <= v < 2.0.0 1.1.1
deadfoxygrandpa/Elm-Test 1.0.2 <= v < 2.0.0 1.1.0



Format String for Elm

by Max Goldstein

Create format strings for dates in the Elm programming language.


The module FormatDate exports one function, formatDate : String -> Date.Date -> String. The Date refers to Elm's standard Date library. The input String may contain any of the following substrings, which will be expanded to parts of the date.

  • %Y - 4 digit year
  • %m - Zero-padded month of year, e.g. "07" for July
  • %B - Full month name, e.g. "July"
  • %b - Abbreviated month name, e.g. "Jul"
  • %d - Zero-padded day of month, e.g "02"
  • %e - Space-padded day of month, e.g " 2"
  • %a - Day of week, abbreviated to three letters, e.g. "Wed"
  • %A - Day of week in full, e.g. "Wednesday"
  • %H - Hour of the day, 24-hour clock, zero-padded
  • %k - Hour of the day, 24-hour clock, space-padded
  • %I - Hour of the day, 12-hour clock, zero-padded
  • %l - (lower ell) Hour of the day, 12-hour clock, space-padded
  • %p - AM or PM
  • %P - am or pm
  • %M - Minute of the hour, zero-padded
  • %S - Second of the minute, zero-padded

Note that %% is intended to produce a literal % but this is not supported yet.


Run the tests using elm-make test.elm --output test.html --yes and viewing test.html in your browser.


Pull requests are welcome! Note that in addition to adding a new letter to the massive case statement, you'll also need to add it to the regex. Languages like Haskell, Python, and Ruby have very comprehensive format strings. (Luckily, they seem to agree on the encoding, which you should follow.) The goal here is different: address 90% of use cases with relative ease. So don't go adding formats just because they'e there.