Created
March 27, 2012 15:15
-
-
Save dergraf/2216802 to your computer and use it in GitHub Desktop.
pretty print timestamps in erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 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