Reputation: 461
I have a date. How can I format it via Times so that it becomes of the format:
Wed, 02 Oct 2002 15:00:00 +0200
or
Wed, 02 Oct 2002 15:00:00 GMT
or
Wed, 02 Oct 2002 15:00:00 EST
I've tried this:
Timex.format!(my_date, "%D, %d %M %Y %H:%i:%s T", :strftime))
but it threw an exception:
%Timex.Format.FormatError{message: {:format, "Expected end of input at line 1, column 16"}} (expected a string)
while it's getting converted into other, simpler, formats with no errors.
Upvotes: 7
Views: 4858
Reputation: 629
Timex.now()|> Timex.format!("%Y-%m-%d %H:%M", :strftime)
output: 2019-05-23 11:06
Upvotes: 4
Reputation: 222158
I believe you're looking for RFC1123
DateTime format:
iex(1)> Timex.now |> Timex.format!("{RFC1123}")
"Sat, 11 Mar 2017 12:04:21 +0000"
iex(2)> Timex.now |> Timex.to_datetime("America/Chicago") |> Timex.format!("{RFC1123}")
"Sat, 11 Mar 2017 06:04:50 -0600"
Upvotes: 6