Просмотр исходного кода

add now_to_ms/0, now_to_ms/1 functions

Feng 10 лет назад
Родитель
Сommit
d8c116a502
1 измененных файлов с 8 добавлено и 4 удалено
  1. 8 4
      src/emqttd_util.erl

+ 8 - 4
src/emqttd_util.erl

@@ -25,10 +25,8 @@
 %%%-----------------------------------------------------------------------------
 -module(emqttd_util).
 
--export([apply_module_attributes/1,
-         all_module_attributes/1,
-         cancel_timer/1,
-         now_to_secs/0, now_to_secs/1]).
+-export([apply_module_attributes/1, all_module_attributes/1, cancel_timer/1,
+         now_to_secs/0, now_to_secs/1, now_to_ms/0, now_to_ms/1]).
 
 -export([integer_to_binary/1]).
 
@@ -94,3 +92,9 @@ now_to_secs() ->
 now_to_secs({MegaSecs, Secs, _MicroSecs}) ->
     MegaSecs * 1000000 + Secs.
 
+now_to_ms() ->
+    now_to_ms(os:timestamp()).
+
+now_to_ms({MegaSecs, Secs, MicroSecs}) ->
+    (MegaSecs * 1000000 + Secs) * 1000 + round(MicroSecs/1000).
+