How to convert datetime() to timestamp() in erlang

大憨熊 提交于 2019-12-10 02:04:11

问题


I need to convert {{2012, 9, 21}, {13, 21, 11}} into timestamp(). How can I do that? Thank you.


回答1:


Corrected version:

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}.



回答2:


You might use this

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

This is part of module from this Github/Arboreus



来源:https://stackoverflow.com/questions/12527908/how-to-convert-datetime-to-timestamp-in-erlang

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!