Use os:timestamp/1 to get now millseconds

This commit is contained in:
Feng Lee 2018-08-12 19:14:14 +08:00
commit 9145fb9ec8
1 changed files with 4 additions and 13 deletions

View File

@ -14,23 +14,14 @@
-module(emqx_time).
-export([seed/0, now_secs/0, now_secs/1, now_ms/0, now_ms/1, ts_from_ms/1]).
-export([seed/0, now_secs/0, now_ms/0]).
seed() ->
rand:seed(exsplus, erlang:timestamp()).
now_ms() ->
os:system_time(milli_seconds).
now_ms({MegaSecs, Secs, MicroSecs}) ->
(MegaSecs * 1000000 + Secs) * 1000 + round(MicroSecs/1000).
now_secs() ->
now_secs(os:timestamp()).
erlang:system_time(second).
now_secs({MegaSecs, Secs, _MicroSecs}) ->
MegaSecs * 1000000 + Secs.
ts_from_ms(Ms) ->
{Ms div 1000000, Ms rem 1000000, 0}.
now_ms() ->
erlang:system_time(millisecond).