wfgilman
Format Time.utc_now() as {HH}:{mm} {a} (e.g. "9:45 am")
Between Elixir Time and Timex I can’t seem to figure out how to get a simple time and format it conventionally. Does anyone know how to do this? I’ve read a bunch of posts that suggest converting Time to erlang time to Timex.DateTime then formatting, but I just cant get it to work
Marked As Solved
Nicd
Have you tried Timex.format(yourtime, "{h12}:{mm} {am}")?
Also Liked
NobbZ
The example (9:45 am) doesn’t match your format spec. For double HH, I’d expect to see a leading zero for single digit hours.
But under the assumption that you use the default formatter, @Nicd’s looks right on a first glance, but it doesn’t understand {mm}, so given your example, the specifier "{h12}:{0m} {am}" should produce it, if though you want a zeropadded hour as I’d expect from HH in other libraries, you need to use {0h12} instead.
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









