Today I Learned: DateTimeParsing in Elixir using Timex

Photo by Steve Johnson on Unsplash

Today I Learned: DateTimeParsing in Elixir using Timex

Pau Riosa's photo
Pau Riosa
ยทMar 16, 2022ยท

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Parse "2021-04-01T14:04:30.444023Z" using Elixir

$ mix deps.get timex

 defmodule DateTimeParser do
   def parsing_time(schedule, timezone) do
     time
     |> Timex.parse!("{ISO:Extended}")
     |> Timex.shift(hours: 24)
     |> Timex.Timezone.convert(timezone)
     |> Timex.format!("%a, %b %d at %l:%M %p", :strftime)
   end
 end

open IEx terminal


 iex > alias DateTimeParser
 iex > scheduled_for = "2021-04-01T14:04:30.444023Z"
 iex > DateTimeParser.parsing_time(scheduled_for, "America/New_York")
 iex > "Fri, Apr 02 at 10:04 AM"
ย 
Share this