calendar:seconds_to_daystime/1
把秒数转为天数和时间
用法:
seconds_to_daystime(Seconds) -> {Days, Time}
内部实现:
-spec seconds_to_daystime(Seconds) -> {Days, Time} when Seconds :: integer(), Days :: integer(), Time :: time(). seconds_to_daystime(Secs) -> Days0 = Secs div ?SECONDS_PER_DAY, Secs0 = Secs rem ?SECONDS_PER_DAY, if Secs0 {Days0 - 1, seconds_to_time(Secs0 + ?SECONDS_PER_DAY)}; true -> {Days0, seconds_to_time(Secs0)} end.
这个函数把给出的时间秒数 Seconds 转为天(days),时(hours),分(minutes),秒(seconds)。
{Total_Wallclock_Time, _Wallclock_Time_Since_Last_Call} = erlang:statistics(wall_clock), {D, {H, M, S}} = calendar:seconds_to_daystime(Total_Wallclock_Time div 1000), lists:flatten(io_lib:format("~p days, ~p hours, ~p minutes and ~p seconds", [D, H, M, S])).
Time 里的值总是一个非负数,如果参数 Seconds 是一个负数,那么 Days 也是一个负数。
calendar:seconds_to_daystime(-123).