0
votes

I use Timex library for getting current time. For example:

iex(9)> time = Timex.now
~U[2019-11-29 14:05:39.759000Z]

When I take the minute, I get the following

iex(10)> time.minute
5

If the current minute is up to 10, then I get a value without a leading zero (the same with hours and seconds). I can get the length of the resulting value and, if it's less than 2, add a zero at the beginning, but I think this is not the best solution

1
Why would you need Timex to get the current time in 2019 btw?Aleksei Matiushkin
@AlekseiMatiushkin I also need to get the names of the day of the week. As far as I know, using standard elixir functions, this cannot be obtainedДенис Корх

1 Answers

1
votes

Try this:

time.minute |> Integer.to_string |> String.pad_leading(2, "0")