Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Datetime 使用Timex格式化日期时间_Datetime_Elixir - Fatal编程技术网

Datetime 使用Timex格式化日期时间

Datetime 使用Timex格式化日期时间,datetime,elixir,Datetime,Elixir,我有个约会。如何通过Times对其进行格式化,使其成为以下格式: Wed, 02 Oct 2002 15:00:00 +0200 或 或 我试过这个: Timex.format!(my_date, "%D, %d %M %Y %H:%i:%s T", :strftime)) 但它抛出了一个例外: %Timex.Format.FormatError{message: {:format, "Expected end of input at line 1, column 16"}} (expec

我有个约会。如何通过Times对其进行格式化,使其成为以下格式:

Wed, 02 Oct 2002 15:00:00 +0200

我试过这个:

 Timex.format!(my_date, "%D, %d %M %Y %H:%i:%s T", :strftime))
但它抛出了一个例外:

%Timex.Format.FormatError{message: {:format, "Expected end of input at line 1, column 16"}} (expected a string)

当它被转换成其他更简单、没有错误的格式时。

我相信您正在寻找
RFC1123
DateTime格式:

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"

输出:2019-05-23 11:06

该格式字符串有多个错误<代码>%D不是星期几,时区是
%Z
(或
%Z
或其他,但不是
T
)。请参阅。您知道为什么此
%a,%d%b%Y%H:%M:%S%z“
给了我“无效的格式字符串,必须至少包含一个指令”。对于我来说,使用
:strftime
作为第三个参数是有效的。您的输出与op所需的输出不匹配。而且,挖掘出一条已经得到op满意答案的旧线索应该再投一次否决票,但唉,我只能投一票。
%Timex.Format.FormatError{message: {:format, "Expected end of input at line 1, column 16"}} (expected a string)
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"
Timex.now()|> Timex.format!("%Y-%m-%d %H:%M", :strftime)