umair-iftikhar

umair-iftikhar

DateTime format issue in Phoenix. Change Time Zone

I am dealing with DateTime in Elixir. I want to change my Time Zone and date format. 2019/02/06 23:10 is my required format here. But when I use <%= "#{NaiveDateTime.utc_now}" %> This 2019-03-01 06:23:20.443620 shown.

I also want to change my timezone. Toronto, ON, Canada (GMT-5)

Most Liked

wojtekmach

wojtekmach

Hex Core Team

By setting applications: key you’re no longer using “application inference” [1], so you’d have to explicitly put all dependencies there if you want them started. The lack of :db_connection in the application list causes the crash.

It’s best not to set applications: key explicitly, and let inference do it’s work. Timex should probably show how to install it with and without application inference, if it doesn’t, I think a PR to update docs is likely to get accepted.

Worth mentioning that as of Elixir v1.8 you no longer need to use Timex to convert between timezones, this functionality is now available in stdlib using DateTime.shift_zone/3. You’d need a timezone database like the one provided by tzdata package [2]

There’re no built-in formatting options other than ISO 8601, so if you need to have a custom format you need to roll your own or bring in Timex. If formatting would be the only reason to bring Timex though, I’d reconsider that.

[1] elixir/CHANGELOG.md at v1.4 · elixir-lang/elixir · GitHub
[2] tzdata | Hex

NobbZ

NobbZ

You need to use Timex, it provides functions for TZ conversion and formatting.

Where Next?

Popular in Discussions Top

matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
sashaafm
I’m trying to evaluate the best combo/stack for a BEAM Web app. Right now I’m exploring Yaws a bit, after having dealt with Phoenix for a...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
ejpcmac
I have discovered Nix last month and I am currently on my way to migrating to it—both on macOS at home and the full NixOS distrubution at...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18146 126
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
hazardfn
I suppose this question is effectively hackney vs. ibrowse but we are at a point in our project where we have to make a choice between th...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
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
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement