Chronos v1.8.0 Chronos.Formatter View Source

The Chronos.Formatter module is used to format date/time tuples.

Link to this section Summary

Functions

The http_date function applies the default format for RFC 822 on a specified date. (RFC 822, updated by RFC 1123)

The strftime formats date/time according to the directives in the given format string

The to_short_date function applies the default short date format to a specified date

Link to this section Functions

The http_date function applies the default format for RFC 822 on a specified date. (RFC 822, updated by RFC 1123)

iex> Chronos.Formatter.http_date({{2012, 12, 21}, { 13, 31, 45 }})
"Fri, 21 Dec 2012 18:31:45 GMT"

Additional options include RFC 850 (obsoleted by RFC 1036) and asctime() format

iex> Chronos.Formatter.http_date({{2012, 12, 21}, { 13, 31, 45 }}, :rfc850)
"Friday, 21-Dec-2012 18:31:45 GMT"

iex> Chronos.Formatter.http_date({{2012, 12, 21}, { 13, 31, 45 }}, :asctime)
"Fri Dec 21 18:31:45 2012"
Link to this function http_date(date_time, atom) View Source
Link to this function iso8601(date_time, timezone) View Source

The strftime formats date/time according to the directives in the given format string.

Format is a string with directives, where directives is a:

%<flags><conversion>

Flags:

  • _ use spaces for padding.
  • 0 use zeros for padding.
  • ^ upcase the result string.

Conversions:

  • Date

    • %Y - Year with century
iex> Chronos.Formatter.strftime({2012, 12, 21}, "%Y")
  "2012"
    • %C - Century
iex> Chronos.Formatter.strftime({2012, 12, 21}, "%C")
  "20"
    • %y - Year without century
iex> Chronos.Formatter.strftime({2012, 12, 21}, "%y")
  "12"
    • %m - Month of the year
iex> Chronos.Formatter.strftime({2012, 12, 21}, "%m")
  "12"

  iex> Chronos.Formatter.strftime({2012, 1, 21}, "%0m")
  "01"

  iex> Chronos.Formatter.strftime({2012, 1, 21}, "%_m")
  " 1"
    • %B - The full month name
iex> Chronos.Formatter.strftime({2012, 12, 21}, "%B")
  "December"

  iex> Chronos.Formatter.strftime({2012, 1, 21}, "%^B")
  "JANUARY"
    • %b - The abbreviated month name
iex> Chronos.Formatter.strftime({2012, 12, 21}, "%b")
  "Dec"

  iex> Chronos.Formatter.strftime({2012, 1, 21}, "%^b")
  "JAN"
    • %d - Day of the month
iex> Chronos.Formatter.strftime({2012, 12, 1}, "%d")
  "1"

  iex> Chronos.Formatter.strftime({2012, 1, 1}, "%_d")
  " 1"

  iex> Chronos.Formatter.strftime({2012, 1, 1}, "%0d")
  "01"
    • %j - Day of the year (001..366)
iex> Chronos.Formatter.strftime({2012, 2, 1}, "%j")
  "32"

  iex> Chronos.Formatter.strftime({2012, 1, 1}, "%j")
  "1"

Examples:

iex> Chronos.Formatter.strftime({2012, 12, 21}, "%Y-%m-%d")
"2012-12-21"

iex> Chronos.Formatter.strftime({2012, 12, 21}, "Presented on %m/%d/%Y")
"Presented on 12/21/2012"

The to_short_date function applies the default short date format to a specified date

iex> Chronos.Formatter.to_short_date({2012, 12, 21})
"2012-12-21"