Skip to content

Instantly share code, notes, and snippets.

@dergraf
Created March 27, 2012 15:15
Show Gist options
  • Save dergraf/2216802 to your computer and use it in GitHub Desktop.
Save dergraf/2216802 to your computer and use it in GitHub Desktop.
pretty print timestamps in erlang
%% pretty print timestamp from lager/src/lager_utils.erl
localtime_ms() ->
{_, _, Micro} = Now = os:timestamp(),
{Date, {Hours, Minutes, Seconds}} = calendar:now_to_local_time(Now),
{Date, {Hours, Minutes, Seconds, Micro div 1000 rem 1000}}.
format_time() ->
format_time(localtime_ms()).
format_time({{Y, M, D}, {H, Mi, S, Ms}}) ->
{io_lib:format("~b-~2..0b-~2..0b", [Y, M, D]),
io_lib:format("~2..0b:~2..0b:~2..0b.~3..0b", [H, Mi, S, Ms])};
format_time({{Y, M, D}, {H, Mi, S}}) ->
{io_lib:format("~b-~2..0b-~2..0b", [Y, M, D]),
io_lib:format("~2..0b:~2..0b:~2..0b", [H, Mi, S])}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment