Date at Megaseconds

Is there any easy way to convert from datetime erlang notation to now / 0 notation?

Basically, I need an inverse function:

{Date, Time} = calendar:now_to_datetime(now()).

So something like

{Megaseconds, Seconds, Microsecods} = datetime_to_now({Date, Time})
+3
source share
1 answer

I clean my question. My google-fu did not warm up, but it seems. The following does exactly what I want.

-define(GREGORIAN_SECONDS_1970, 62167219200).

datetime_to_now(DateTime) ->
    GSeconds = calendar:datetime_to_gregorian_seconds(DateTime),
    ESeconds = GSeconds - ?GREGORIAN_SECONDS_1970,
    {ESeconds div 1000000, ESeconds rem 1000000, 0}.
+2
source

Source: https://habr.com/ru/post/1763895/


All Articles