Erlang中文手册(Erldoc.com)  »  calendar  »  gregorian_seconds_to_datetime/1
Erlang并发编程 Erlang/OTP设计原理 Erlang/OTP[pdf] Mnesia用户手册[pdf] Erlang完整手册[en] 官网手册[en] 模块列表 方法列表 随机 Erlang中文社区(BBS) 美女图库

calendar:gregorian_seconds_to_datetime/1

从给定的公历秒数里计算出日期和时间

用法:

gregorian_seconds_to_datetime(Seconds) -> datetime()

内部实现:

%% gregorian_seconds_to_datetime(Secs)
%%
-spec gregorian_seconds_to_datetime(Seconds) -> datetime() when
      Seconds :: non_neg_integer().
gregorian_seconds_to_datetime(Secs) when Secs >= 0 ->
    Days = Secs div ?SECONDS_PER_DAY,
    Rest = Secs rem ?SECONDS_PER_DAY,
    {gregorian_days_to_date(Days), seconds_to_time(Rest)}.

把给定的公历秒数 Seconds (从 1970-1-1 00:00:00 开始)转换成日期和时间。

StartTime = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
{MegaSecs, Secs, _MicroSecs} = erlang:now(),
Seconds = MegaSecs * 1000000 + Secs,
calendar:gregorian_seconds_to_datetime(Seconds + StartTime).
StartTime = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
calendar:gregorian_seconds_to_datetime(1 + StartTime).
StartTime = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
calendar:gregorian_seconds_to_datetime(1234567890 + StartTime).
阿里云 - 最高1000元通用代金券立即可用
沪ICP备13037221号-9