> Erlang中文手册 > now_to_universal_time/1 把当前世界转为世界通用世界(UTC)

calendar:now_to_universal_time/1

把当前世界转为世界通用世界(UTC)

用法:

now_to_universal_time(Now) -> datetime1970()

内部实现:

%% now_to_universal_time(Now)
%% now_to_datetime(Now)
%%
%% Convert from now() to UTC.
%%
%% Args: Now = now(); now() = {MegaSec, Sec, MilliSec}, MegaSec = Sec
%% = MilliSec = integer() 
%% Returns: {date(), time()}, date() = {Y, M, D}, time() = {H, M, S}.
%% 
-spec now_to_datetime(Now) -> datetime1970() when
      Now :: erlang:timestamp().
now_to_datetime({MSec, Sec, _uSec}) ->
    Sec0 = MSec*1000000 + Sec + ?DAYS_FROM_0_TO_1970*?SECONDS_PER_DAY,
    gregorian_seconds_to_datetime(Sec0).

-spec now_to_universal_time(Now) -> datetime1970() when
      Now :: erlang:timestamp().
now_to_universal_time(Now) ->
    now_to_datetime(Now).

这个函数跟 calendar:now_to_datetime/1 一样,都是把从 erlang:now/0 返回的值转换为世界通用世界(UTC)。

calendar:now_to_universal_time(erlang:now()).
calendar:now_to_universal_time(os:timestamp()).