Elixir String To Datetime

[Solved] Elixir String To Datetime | Elixir - Code Explorer | yomemimo.com
Question : elixir string to datetime

Answered by : nasty-nightingale-6kbfxg59j1af

defmodule SomeModule do @doc """ iex> SomeModule.to_date("2020-01-30") ~D[2020-01-30] """ def to_date(string), do: Date.from_iso8601!(string) @doc """ iex> SomeModule.to_date_time("1997-07-16T19:20:30.45Z") ~U[1997-07-16 19:20:30.45Z] """ def to_date_time(string) do case DateTime.from_iso8601(string) do {:ok, date_time, _offset} -> date_time error -> error end end
end

Source : | Last Update : Sun, 22 May 22

Answers related to elixir string to datetime

Code Explorer Popular Question For Elixir