1
我正在使用下面的代碼格式化秒到mm:ss格式。有更好的選擇嗎?有沒有更好的方法在Elixir中將秒數格式化爲mm:ss格式?
def formatted_length(length) do
minutes =
length/60
|> Float.floor()
|> round()
|> Integer.to_string()
seconds =
rem(length, 60)
|> Integer.to_string()
|> String.rjust(2, ?0)
minutes <> ":" <> seconds
end