Muz*_*hua 3 unix erlang timezone mnesia
我正在与远程服务器进行交互.此远程服务器位于不同的时区.部分身份验证要求我生成:
"The number of seconds since January 1, 1970 00:00:00 GMT The server will only accept requests where the timestamp is within 600s of the current time"
的文件erlang:now().揭示它可以让我the elapsed time since 00:00 GMT, January 1, 1970 (zero hour)
on the assumption that the underlying OS supports this.它返回一个size=3元组{MegaSecs, Secs, MicroSecs}.我尝试使用,element(2,erlang:now())但远程服务器发送给我这条消息:
Timestamp expired: Given timestamp (1970-01-07T14:44:42Z) not within 600s of server time (2012-01-26T09:51:26Z)自1970年1月1日起,这三个参数中的哪一个是所需的秒数?我做的不对吗?是不是我必须用做
universal time在calendar:universal_time() ?
seconds_1970()->
T1 = {{1970,1,1},{0,0,0}},
T2 = calendar:universal_time(),
{Days,{HH,Mins,Secs}} = calendar:time_difference(T1,T2),
(Days * 24 * 60 * 60) + (HH * 60 * 60) + (Mins * 60) + Secs.
但问题仍然存在.必须有一种方法,一种基本的Erlang方式来获得这个,可能是BIF,对吗?
您必须从结果中计算UNIX时间(自1970年以来的秒数)now(),如下所示:
{MegaSecs, Secs, MicroSecs} = now().
UnixTime = MegaSecs * 1000000 + Secs.
Run Code Online (Sandbox Code Playgroud)
只使用元组的第二个条目将告诉您自上一个十进制万亿分钟以来的秒数(自UNIX纪元以来的秒数).
[2017编辑]
now已弃用,但erlang:timestamp()不是,并返回与之相同的格式now.