Elixir: string in datetime

Anyone lucky with the function Stringto DateTimeat the Elixir or Phoenix? The documentation has nothing to do with the function parse/1.

Preferably from a line that looks like this:

08/02/2016 6:15 PM
+4
source share
1 answer

There is no such function in Elixir or Phoenix. Ecto has some basic datetime parsers, but they cannot parse the example string you posted. For this you can use the datetime library, for example timex. Here's how you could parse the example string using timex:

iex(1)> Timex.parse("08/02/2016 6:15 PM", "{0D}/{0M}/{YYYY} {h12}:{m} {AM}")
{:ok, ~N[2016-02-08 18:15:00]}

(Swap 0D 0M, 2 8 .)

+9

Source: https://habr.com/ru/post/1649844/


All Articles