Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR ELIXIR

elixir string to time

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
 
PREVIOUS NEXT
Tagged: #elixir #string #time
ADD COMMENT
Topic
Name
7+9 =