From d8c116a5020e8ab809d26c3bd9eb631d721ea62f Mon Sep 17 00:00:00 2001 From: Feng Date: Mon, 25 Jan 2016 12:59:41 +0800 Subject: [PATCH] add now_to_ms/0, now_to_ms/1 functions --- src/emqttd_util.erl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/emqttd_util.erl b/src/emqttd_util.erl index 0cee8e0d4..29b87b661 100644 --- a/src/emqttd_util.erl +++ b/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). +