简体   繁体   中英

Elixir/Phoenix - get current time (Timex library)

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

尝试这个:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM