@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 elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/37c433b7-ee09-4052-911c-f58e2904be14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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.
On Wed, Aug 30, 2017 at 6:11 PM, Fernando Tapia Rico <fert...@gmail.com> 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 elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/48a9a668-010c-4a6e-a820-01b4f17ad245%40googlegroups.com.