[erlang-questions] Working with dates.

Ben Hood <>
Mon Jul 16 08:24:14 CEST 2007


-define(MegaSeconds, 1000000000).
-define(Seconds, 1000).
-define(MicroSeconds, 1000).

-define(UnixEpoch, 62167219200).

encode_timestamp({MegaSecs, Secs, MicroSecs}) ->
    MegaSecs * ?MegaSeconds + Secs * ?Seconds + MicroSecs / ?MicroSeconds.

encode_localtime(DateTime={{Year,Month,Day},{Hour,Min,Sec}}) ->
    [Universal] = calendar:local_time_to_universal_time_dst(DateTime),
    Seconds = calendar:datetime_to_gregorian_seconds(Universal),
    (Seconds - ?UnixEpoch) * 1000.

HTH,

Ben

> 1) Are there functions in OTP to convert unix timestamp <--> the tuple
> format used in Erlang?



More information about the erlang-questions mailing list