erikmiller
Converting a datetime object without any tz information into one that has timezone info without adjusting based on offset from UTC
I have a date time object that is getting returned from a database with no associated timezone data (YYYY-MM-DD HH:MM:SS.mmmm). I know the information is in the America/New_York timezone.
But since there is no timezone with the date/time, when I try to save it in a format with a timezone it uses UTC.
When trying to save it in the correct timezone using Timex the time value changes by the offset and is no longer correct.
For example I have a datetime of ‘2017-03-08T17:04:10’ in the database that gets converted to datetime(2017-03-08T17:04:10Z Etc/UTC)
I want it to be changed to datetime(2017-03-08T17:04:10-05:00 America/New_York)
IE the numbers for year and time are all the same, but the timezone is different.
I thought about just appending the ‘-05:00’ and reparsing the string using Timex format/parse, but I want it to work with daylight savings time.
I haven’t been able to locate the Timex functionality to do this. Does anyone know if it exists?
First Post!
chensan
I think you can convert it with Timex.Timezone — timex v3.7.13 first, then shift Timex — timex v3.7.13 the converted time.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









