How to calculate Time

Ulf Wiger <>
Mon Jun 10 10:01:07 CEST 2002


On Mon, 10 Jun 2002, K Chandra Shekhar wrote:

>hi guys,
>
>Is there any BIF to calculate the time(in secs or mins)  for
>which an alarm is active ?


No BIF, but take a look at calendar:time_difference(T1, T2).

If you store the times using erlang:now(), you may use the
following formula:

diff({M,S,U}, {M,S1,U1}) ->
    ((S-S1) * 1000) + ((U-U1) div 1000);
diff({M,S,U}, {M1,S1,U1}) ->
    ((M-M1)*1000000+(S-S1))*1000 + ((U-U1) div 1000).


/Uffe
-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks




More information about the erlang-questions mailing list