如何在Erlang/OTP中将datetime()转换为timestamp()?

yh2wf1be  于 2022-12-08  发布在  Erlang
关注(0)|答案(2)|浏览(138)

我需要将{{2012, 9, 21}, {13, 21, 11}}转换为timestamp()
我怎么能那样做呢?

hl0ma9xz

hl0ma9xz1#

更正版本:

Seconds = calendar:datetime_to_gregorian_seconds(DateTime) - 62167219200,
%% 62167219200 == calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}})
{Seconds div 1000000, Seconds rem 1000000, 0}.
dhxwm5r4

dhxwm5r42#

你可以用这个

to_timestamp({{Year,Month,Day},{Hours,Minutes,Seconds}}) ->
(calendar:datetime_to_gregorian_seconds(
    {{Year,Month,Day},{Hours,Minutes,Seconds}}
) - 62167219200)*1000000;

这是来自此Github/Arboreus的模块的一部分

相关问题