marcuslankenau

marcuslankenau

Parse local datetime with timex

I am struggling to parse a local datetime with timex.

The datetime string is like “26/10/2018 10:00” and I know it is CET or CEST. I managed to parse it with:

Timex.parse!(time_str, "{0D}/{0M}/{YYYY} {h24}:{m}")

I then receive the time in utc which is wrong. I could convert it to cet with

Timex.Timezone.convert("Europe/Berlin")

But then I get 12:00 CEST and not 10:00 CEST.

I tried adding the timezone to the datetime string, but I need the offset to parse with %Z, I dont know the offset.

Any ideas?

Most Liked

wojtekmach

wojtekmach

Hex Core Team

Use Timex.to_datetime/2:

iex> Timex.parse!("26/10/2018 10:00", "{0D}/{0M}/{YYYY} {h24}:{m}") |> Timex.to_datetime("Europe/Berlin")
#DateTime<2018-10-26 10:00:00+02:00 CEST Europe/Berlin>
marcuslankenau

marcuslankenau

Thx, that was quick… and it worked.

Last Post!

gabriel137

gabriel137

Thaaanks, you saved my day

Where Next?

Popular in Questions Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement