Skip to content

Instantly share code, notes, and snippets.

@DimitryDushkin
Created May 7, 2013 12:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DimitryDushkin/5532071 to your computer and use it in GitHub Desktop.
Save DimitryDushkin/5532071 to your computer and use it in GitHub Desktop.
Erlang get current time in milliseconds
-spec get_timestamp() -> integer().
get_timestamp() ->
{Mega, Sec, Micro} = os:timestamp(),
(Mega*1000000 + Sec)*1000 + round(Micro/1000).
@mmbrian
Copy link

mmbrian commented Nov 30, 2014

Thank you!

@joakimk
Copy link

joakimk commented Sep 19, 2015

Elixir version of this in case anyone wants it.

defp system_time do                                                                                                                                                                                   
  {mega, seconds, ms} = :os.timestamp()                                                                                                                                                               
  (mega*1000000 + seconds)*1000 + :erlang.round(ms/1000)                                                                                                                                              
end

If you are on Erlang 18 or newer, look into using :erlang.system_time instead of this.

@deverlex
Copy link

thanks

@dylan-chong
Copy link

Thanks @joakimk . :erlang.system_time / 1.0e6 |> round works to get the millis

@bartekupartek
Copy link

there is Erlang function to get timestamp in ms :os.system_time(:millisecond)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment