You can also use System.system_time/1 as well. On Wed, Aug 30, 2017 at 6:34 PM Fernando Tapia Rico <[email protected]> wrote:
> Thanks for the prompt reply! > > I didn't know about :os.system_time(:second), that's exactly what I was > looking for. > > > It doesn't make a whole lot of sense to me to have a function on > DateTime that doesn't produce or accept a DateTime. > > You are completely right :) > > On Thursday, August 31, 2017 at 1:21:41 AM UTC+2, Allen Madsen wrote: > >> It doesn't make a whole lot of sense to me to have a function on DateTime >> that doesn't produce or accept a DateTime. >> >> You can use :os.system_time() or :os.system_time(:second) if you want to >> get straight to the unix time. >> > >> Allen Madsen >> http://www.allenmadsen.com >> >> On Wed, Aug 30, 2017 at 6:11 PM, Fernando Tapia Rico <[email protected]> >> wrote: >> > It's a little shortcut but it's the most used method in all the `utils.ex` >>> of my projects. >>> >>> @doc """ >>> Returns the current datetime in Unix time. >>> >>> It will return the integer with the given unit, according to >>> `System.convert_time_unit/3`. >>> """ >>> @spec now_unix(System.time_unit) :: integer >>> def now_unix(unit \\ :second) do >>> DateTime.utc_now() |> DateTime.to_unix(unit) >>> end >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "elixir-lang-core" group. >>> >> To unsubscribe from this group and stop receiving emails from it, send an >>> email to [email protected]. >> >> >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/elixir-lang-core/37c433b7-ee09-4052-911c-f58e2904be14%40googlegroups.com >>> <https://groups.google.com/d/msgid/elixir-lang-core/37c433b7-ee09-4052-911c-f58e2904be14%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/48a9a668-010c-4a6e-a820-01b4f17ad245%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/48a9a668-010c-4a6e-a820-01b4f17ad245%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK%3D%2B-Ts3cBykY2yd8ffX99uonqXMbNNQ8WcG2OPgN65DB3oNRA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
