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

Ulf Wiger (TN/EAB) <>
Tue Nov 4 16:07:14 CET 2008


Joel Reymont skrev:
> 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?

I think that's the most common way to do it.

Remember that you must stay within a "smallint"
with the timer. To protect yourself from clock
changes etc., you might want to sleep in smallish
increments (perhaps minutes or seconds at a time,
depending on what trade-off between safety and
overhead that suits you best.)

BR,
Ulf W



More information about the erlang-questions mailing list