Formatting a date-time using Timex

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 17:03:43

问题


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.


回答1:


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"



回答2:


Timex.now()|> Timex.format!("%Y-%m-%d %H:%M", :strftime)

output: 2019-05-23 11:06



来源:https://stackoverflow.com/questions/42734873/formatting-a-date-time-using-timex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!