Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert timestamp to DateTime in Elixir?

Tags:

elixir

ecto

How to convert the time in milliseconds to Ecto.DateTime?

The time in milliseconds is the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.

like image 496
Alex Craft Avatar asked Jun 19 '16 09:06

Alex Craft


2 Answers

To convert timestamps to DateTime

DateTime.from_unix(1466298513463, :millisecond)

For more Details https://hexdocs.pm/elixir/master/DateTime.html#from_unix/3

like image 135
Ali Adnan Avatar answered Nov 17 '22 06:11

Ali Adnan


Now it's very simple to do:

timestamp |> DateTime.from_unix!(:millisecond) |> Ecto.DateTime.cast!
like image 27
darkbaby123 Avatar answered Nov 17 '22 08:11

darkbaby123