A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since the Unix epoch. Here’s how to do it in Elixir.
Use DateTime.utc_now() to get the current UTC time. Then, use DateTime.to_unix/2 to get elapsed time since the Unix epoch in seconds, milliseconds, or nanoseconds.
You can also convert integer seconds or nanoseconds since the epoch into the corresponding DateTime using DateTime.from_unix!/2.
To run the program:
Next, we’ll look at another time-related task: time parsing and formatting.