I am looking for opportunity to convert DateTime to unix timestamp. Is there any function that handle it?
You can convert a DateTime to a unix timestamp by using DateTime.to_unix/2:
datetime = DateTime.utc_now()
DateTime.to_unix(datetime)
If you just want the current timestamp: System.os_time/1:
iex> System.os_time()
1663383246024939000
iex> System.os_time(:second)
1663383248
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With