Kalends.DateTime.Format

Summary

httpdate(dt)

Takes a DateTime. Returns a string with the date-time in RFC 2616 format. This format is used in the HTTP protocol. Note that the date-time will always be "shifted" to UTC

iso8601(dt)

Takes a DateTime. Returns a string with the time in ISO 8601

strftime!(dt, string, lang \\ :en)

Generate a string from a DateTime formatted by a format string. Similar to strftime! known from UNIX. A list of the letters and and what they do are available here: http://man7.org/linux/man-pages/man3/strftime.3.html

Functions

httpdate(dt)

Takes a DateTime. Returns a string with the date-time in RFC 2616 format. This format is used in the HTTP protocol. Note that the date-time will always be "shifted" to UTC.

Example

# The time is 6:09 in the morning in Montevideo, but 9:09 GMT/UTC.
iex> DateTime.from_erl!({{2014, 9, 6}, {6, 9, 8}}, "America/Montevideo") |> DateTime.Format.httpdate
"Sat, 06 Sep 2014 09:09:08 GMT"
iso8601(dt)

Takes a DateTime. Returns a string with the time in ISO 8601

Example

iex> Kalends.DateTime.from_erl!({{2014, 9, 26}, {17, 10, 20}}, "America/Montevideo") |> Kalends.DateTime.Format.iso8601
"2014-09-26T17:10:20-03:00"
strftime!(dt, string, lang \\ :en)

Generate a string from a DateTime formatted by a format string. Similar to strftime! known from UNIX. A list of the letters and and what they do are available here: http://man7.org/linux/man-pages/man3/strftime.3.html

Example

iex> DateTime.from_erl!({{2014,9,6},{17,10,20}},"UTC") |> DateTime.Format.strftime! "%A %Y-%m-%e %H:%M:%S"
"Saturday 2014-09- 6 17:10:20"

iex> DateTime.from_erl!({{2014,9,6},{17,10,20}},"UTC") |> DateTime.Format.strftime! "%a %d.%m.%y"
"Sat 06.09.14"

iex> DateTime.from_erl!({{2014,9,6},{17,10,20}},"UTC") |> DateTime.Format.strftime! "%A %d/%m/%Y", :da
"lørdag 06/09/2014"
conversion spec. Description Example
%a Abbreviated name of day Mon
%A Full name of day Monday
%b Abbreviated month name Jan
%h (Equivalent to %b)
%B Full month name January
%j Day of the year as a decimal number (001 to 366) 002
%u
%w
%V
%G
%g
%y
%Y
%C
%I
%l
%P
%p
%r
%R
%T
%F
%m
%e
%d
%H
%k
%M
%S
%z
%Z