[erlang-questions] setting a timer for a given date and time

Oscar Hellström oscar@REDACTED
Tue Nov 4 18:13:48 CET 2008


Just to keep myself busy.

Hynek Vychodil wrote:
> I haven't found ({Date, Time}) -> {MegaSecs, Secs, MicroSecs} function.

% calendar:datetime_to_gregorian_seconds({{1970,1,1}, {0,0,0}})
-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}.


> On Tue, Nov 4, 2008 at 5:00 PM, Oscar Hellström
> <oscar@REDACTED <mailto:oscar@REDACTED>> wrote:
> 
>     How about timer:now_diff/2
> 
>     Hynek Vychodil wrote:
>     > calendar:time_difference/2 is signed as deprecated in documentation.
>     >
>     > On Tue, Nov 4, 2008 at 4:00 PM, Joel Reymont <joelr1@REDACTED
>     <mailto:joelr1@REDACTED>
>     > <mailto:joelr1@REDACTED <mailto:joelr1@REDACTED>>> wrote:
>     >
>     >     What is a robust way of setting a timer for a given UTC date
>     and time?
>     >
>     >     I guess I can take the difference between now (UTC) and the given
>     >     datetime using calendar:time_difference/2. This would give me
>     seconds
>     >     which I could multiply by 1000 to get the milliseconds the timer
>     >     needs.
>     >
>     >     Would this be the best approach, though?
>     >
>     >        Thanks, Joel
>     >
>     >     --
>     >     http://wagerlabs.com
>     >     _______________________________________________
>     >     erlang-questions mailing list
>     >     erlang-questions@REDACTED
>     <mailto:erlang-questions@REDACTED>
>     <mailto:erlang-questions@REDACTED
>     <mailto:erlang-questions@REDACTED>>
>     >     http://www.erlang.org/mailman/listinfo/erlang-questions
>     >
>     >
>     >
>     >
>     > --
>     > --Hynek (Pichi) Vychodil
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > erlang-questions mailing list
>     > erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>     > http://www.erlang.org/mailman/listinfo/erlang-questions
> 
>     Best regards
>     --
>     Oscar Hellström, oscar@REDACTED
>     <mailto:oscar@REDACTED>
>     Office: +44 20 7655 0337
>     Mobile: +44 798 45 44 773
>     Erlang Training and Consulting
>     http://www.erlang-consulting.com/
> 
> 
> 
> 
> -- 
> --Hynek (Pichi) Vychodil


-- 
Oscar Hellström, oscar@REDACTED
Office: +44 20 7655 0337
Mobile: +44 798 45 44 773
Erlang Training and Consulting
http://www.erlang-consulting.com/



More information about the erlang-questions mailing list