We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Handling Time Zones in Phoenix LiveView
18
clicks

Source: mikezornek.com
The article outlines how to display DateTime values, like published_at and closed_at, in the user's local time zone within a Phoenix LiveView application. The author explains that, by default, Elixir only handles DateTime values in the Etc/UTC time zone and requires a time zone database for any other time zones. They specifically chose the tzdata library for this implementation, detailing how to configure it in a Phoenix project. The author describes the challenge of not knowing the user's time zone from the HTTP request and suggests using JavaScript to retrieve the time zone, which can then be passed to the LiveView. Once this value is obtained, the DateTime values can be converted for display using DateTime.shift_zone/2. The article also notes that a full implementation can be found in a specific Flick PR. Additionally, the author discusses the issue of the DateTime initially displaying in UTC before switching to the user's time zone when the WebSocket connection is established. They propose a potential solution using fallback time zones for a previous project to improve the user experience. Finally, the author provides resources for further learning.
Related posts
© HashMerge 2025