Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert datetime to timestamp in Elixir

I am looking for opportunity to convert DateTime to unix timestamp. Is there any function that handle it?

like image 840
Rudziankoŭ Avatar asked May 10 '26 00:05

Rudziankoŭ


1 Answers

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
like image 131
Adam Millerchip Avatar answered May 11 '26 15:05

Adam Millerchip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!