Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert datetime() to timestamp() in Erlang/OTP?

Tags:

erlang

I need to convert {{2012, 9, 21}, {13, 21, 11}} into timestamp().

How can I do that?

like image 283
Kirill Trofimov Avatar asked Sep 21 '12 09:09

Kirill Trofimov


2 Answers

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}.
like image 51
Alexey Romanov Avatar answered Nov 19 '22 13:11

Alexey Romanov


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

like image 2
Alexandr Kirilov Avatar answered Nov 19 '22 14:11

Alexandr Kirilov