Converting time to remedial human form?

The Elixir docs on time have a ton of choices:

I want something like

3/11/23 5:22 pm

Does anyone have a suggestion as to where I can direct my attention to? I’m assuming their are modules to help with this, and that I don’t need to code up a 100 percent solution from unix time from scratch.

Hi @wktdev the function you’re looking for is Calendar — Elixir v1.14.3

Give it a whirl and let me know if you run into snags.

1 Like

Do I do something like this:

date_capture = DateTime.utc_now()

strftime(date_capture, string_format, user_options \\ [])

I’ve just thrown in the towel attempting to read Elixir documentation.
I have no idea what the string format syntax is or the user_options.

If the docs had an example I could copy and paste and get a working output from , I could work backwards quickly.

I don’t know what the caveats like this mean:

if you use %Y to format the year, the datetime must have the :year field

Again, there are no examples to work from - so there is no context.

Try Calendar — Elixir v1.15.0-dev for examples.

Edit: the link looks just like I changed the version, but it’s actually #anchored a ways down the page to the right function, ‘strftime’. There are examples like:

iex> Calendar.strftime(~U[2019-08-26 13:52:06.0Z], "%a, %B %d %Y")
"Mon, August 26 2019"

When I said example I mean working example where I can paste something in the console and see a result.

Like this:

The MDN documentation is designed to ride the grain of how people actually learn.

Oh I see. There is an example but it’s down at the bottom of the page.

Right, in this case the function has relatively long documentation, because there are a lot of options. If you scroll through all of it for that function you’ll see plenty of examples.

I’ve run into this myself. Examples are further down the page, and the exceptions/caveats – the most useful fact given the problem I’m facing at times (!) – is the last sentence of the docs.

Yeah I think the docs for Calendar.strftime/3 could be improved. I’m hoping that making it more clear that the Options section is really about the user_options argument it will make it easier to ignore the Options section and focus on the “Formats”.

So I’ve created a PR that will hopefully make it easier to read/scan/grok the Calendar.strftime/3 docs:

P.S. I also thought about putting an example up higher in the docs but I’m not aware of any other function doc that does that (although perhaps one does exist).

Edit: and the PR is now merged, and it includes an example much further up in the docs :tada: