[erlang-questions] Unix Epoch

Henning Diedrich hd2010@REDACTED
Sun May 2 17:22:55 CEST 2010


That's what I would hope for, this leaves

datetime_to_gregorian_seconds({Date,Time})

which is also, and needlessly, calculated back to year 0.



Rapsey wrote:
> Epoch seconds from 0 is a constant. So no need to calculate it every time.
>
>
> Sergej
>
> On Sun, May 2, 2010 at 3:33 PM, Henning Diedrich <hd2010@REDACTED>wrote:
>
>   
>> Hi,
>>
>> is there a better way to turn datetime into unix epoch seconds?
>>
>> unix_time({Date,Time}) ->
>>
>>   UnixEpoch = {{1970,1,1},{0,0,0}},
>>   calendar:datetime_to_gregorian_seconds({Date,Time}) -
>> calendar:datetime_to_gregorian_seconds(UnixEpoch).
>>
>> Gregorian seconds down to year 0 might be a costly calculation I though.
>>
>> Thanks!
>> Henning
>>
>>     
>
>   


More information about the erlang-questions mailing list