refactor: expose rfc3339 datetime string

This commit is contained in:
Zaiming (Stone) Shi 2022-06-13 11:56:07 +02:00
parent 4ac151c9d8
commit 10add62206
2 changed files with 1 additions and 28 deletions

View File

@ -119,12 +119,7 @@ uptime() ->
%% @doc Get sys datetime
-spec datetime() -> string().
datetime() ->
{{Y, M, D}, {H, MM, S}} = calendar:local_time(),
lists:flatten(
io_lib:format(
"~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", [Y, M, D, H, MM, S]
)
).
calendar:system_time_to_rfc3339(erlang:system_time(), [{unit, nanosecond}]).
sys_interval() ->
emqx:get_config([sys_topics, sys_msg_interval]).

View File

@ -17,8 +17,6 @@
-module(emqx_mgmt_util).
-export([
strftime/1,
datetime/1,
kmg/1,
ntoa/1,
merge_maps/2,
@ -51,26 +49,6 @@
-define(MB, (1024 * 1024)).
-define(GB, (1024 * 1024 * 1024)).
%%--------------------------------------------------------------------
%% Strftime
%%--------------------------------------------------------------------
strftime({MegaSecs, Secs, _MicroSecs}) ->
strftime(datetime(MegaSecs * 1000000 + Secs));
strftime(Secs) when is_integer(Secs) ->
strftime(datetime(Secs));
strftime({{Y, M, D}, {H, MM, S}}) ->
lists:flatten(
io_lib:format(
"~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", [Y, M, D, H, MM, S]
)
).
datetime(Timestamp) when is_integer(Timestamp) ->
Epoch = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
Universal = calendar:gregorian_seconds_to_datetime(Timestamp + Epoch),
calendar:universal_time_to_local_time(Universal).
kmg(Byte) when Byte > ?GB ->
kmg(Byte / ?GB, "G");
kmg(Byte) when Byte > ?MB ->