Convert string Datetime to milliseconds
- Timex.parse(startDay, "%Y-%m-%d %H:%M:%S", :strftime)
- startDay = "2016-08-03 00:00:00"
How can I parse and convert the date "2016-08-03 00:00:00" to milliseconds like java.util.Date.getTime() Thanks
like so:
iex(1)> startDay = "2016-08-03 00:00:00"
"2016-08-03 00:00:00"
iex(2)> date = Timex.parse!(startDay, "%Y-%m-%d %H:%M:%S", :strftime)
~N[2016-08-03 00:00:00]
iex(3)> DateTime.to_unix(Timex.to_datetime(date), :milliseconds)
note that the result of the parse is a NaiveDateTime. You need to specify a timezone in order to get unix millis from that. The code above assumes UTC. Note that this code works in elixir >= 1.3
Thanks
Em 25/10/2016 14:20, "Jonas Adler" [email protected] escreveu:
like so:
iex(1)> startDay = "2016-08-03 00:00:00" "2016-08-03 00:00:00" iex(2)> date = Timex.parse!(startDay, "%Y-%m-%d %H:%M:%S", :strftime)~N[2016-08-03 00:00:00] iex(3)> DateTime.to_unix(Timex.to_datetime(date), :milliseconds)
not the the result of the parse is a NaiveDateTime. You need to specify a timezone in order to get unix millis from that. The code above assumes UTC
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bitwalker/timex/issues/227#issuecomment-256084439, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfj5uPmuY0vK6yiQXxwJpw1kR7ZoYecks5q3iwwgaJpZM4Kc2W7 .