Format date with Elixir

Bitwise picture Bitwise · Dec 13, 2017 · Viewed 12.5k times · Source

I'm trying to format the Timex module to look a certain way. I'm trying to get today's date. but I want it formatted like this:

2017/12/12.

year/mn/day

In ruby I would go to the strftime class but I'm not sure how to do this with Elixir:

Current attempt:

Timex.local => #DateTime<2017-12-12 19:57:17.232916-05:00 EST America/Detroit>

How can I take that and format it how I specified?

Answer

tres picture tres · Mar 21, 2021

Elixir 1.11 has Calendar.strftime/3 built-in for your strftime needs.

Calendar.strftime(~U[2019-08-26 13:52:06.0Z], "%y-%m-%d %I:%M:%S %p")
"19-08-26 01:52:06 PM"