# Anyone using input fields of type "datetime-local"? How to get Posix from that?

**URL:** <https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340>\
**Category:** Learn\
**Created:** [April 20, 2022, 8:57am UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340 "2022-04-20T08:57:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmidden](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pmidden/32/4551_2.png) [@pmidden](https://discourse.elm-lang.org/u/pmidden)\
**Post date:** [April 20, 2022, 8:57am UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/1 "2022-04-20T08:57:15Z")

</div>

I’d love to use `<input type="datetime-local"` in my Elm app, but the output of that field seems to be of the form “YYYY-MM-DDTHH:MM”, and I’d like to send a plain `Posix` to the server. What’s a good way to convert that, given I already acquired a `Zone`?

---

<div class="post-metadata">

**Author:** ![Augustin82](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/augustin82/32/1591_2.png) [@Augustin82](https://discourse.elm-lang.org/u/Augustin82)\
**Post date:** [April 20, 2022, 9:07am UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/2 "2022-04-20T09:07:32Z")

</div>

Hi! You could manually split the string and use something like [Time.Extra - time-extra 1.1.1](https://package.elm-lang.org/packages/justinmimbs/time-extra/latest/Time-Extra#partsToPosix) to construct the Posix.

---

<div class="post-metadata">

**Author:** ![Carsten\_Konig](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carsten_konig/32/4063_2.png) [@Carsten\_Konig](https://discourse.elm-lang.org/u/Carsten_Konig)\
**Post date:** [April 20, 2022, 12:56pm UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/3 "2022-04-20T12:56:58Z")

</div>

it’s a bit of a hack but you can have a look at [Iso8601](https://package.elm-lang.org/packages/rtfeldman/elm-iso8601-date-strings/latest/Iso8601) and maybe append the timezone to you string before parsing it or you deal with the timezone after you got UTC back

* * *

I hope you don’t mind a little advice:

Usually we try to always store/transfer etc. datetime-values based on UTC (Posix is fine too) - if you know that every value is based on +0 timezone you get into way less trouble with miss-matches/assumptions about which side/code (client, server, display, repository,…) has to handle local time.

Local-Timezones are only ever dealt with when displaying a time to the user (or receiving an time-input from a user)

---

<div class="post-metadata">

**Author:** ![pmidden](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pmidden/32/4551_2.png) [@pmidden](https://discourse.elm-lang.org/u/pmidden)\
**Post date:** [April 20, 2022, 2:28pm UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/4 "2022-04-20T14:28:57Z")

</div>

I don’t mind and even appreciate the advice! I’m also a bit torn on the issue. I’d love for the client to take the user’s time zone and send UTC to the server. That’s what I’m doing when I’m getting data from the server. However, with this `datetime-local`, I have a string that doesn’t have a time zone. And I cannot extend it properly with a time zone, at least not with the functions that elm/time provides - or can I?

---

<div class="post-metadata">

**Author:** ![Carsten\_Konig](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carsten_konig/32/4063_2.png) [@Carsten\_Konig](https://discourse.elm-lang.org/u/Carsten_Konig)\
**Post date:** [April 20, 2022, 2:51pm UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/5 "2022-04-20T14:51:27Z")

</div>

I’m sure there is a package somewhere that let’s you get the hour-offset for a `Zone` but you can actually _hack_ your way with what `time` provides by (ab)using [`toHour`](https://package.elm-lang.org/packages/elm/time/latest/Time#toHour) - the example there basically gives the hint 😉 - use `millisToPosix` to get a `Posix` for `0` and then subtract what you get from `toHour` to get the offset in hours.

---

<div class="post-metadata">

**Author:** ![pmidden](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pmidden/32/4551_2.png) [@pmidden](https://discourse.elm-lang.org/u/pmidden)\
**Post date:** [April 21, 2022, 7:32am UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/6 "2022-04-21T07:32:44Z")

</div>

That’s the solution I went for and it works beautifully, thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 1, 2022, 7:32am UTC](https://discourse.elm-lang.org/t/anyone-using-input-fields-of-type-datetime-local-how-to-get-posix-from-that/8340/7 "2022-05-01T07:32:54Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
