Skip to content

Instantly share code, notes, and snippets.

@AKB428
Created November 3, 2015 18:36
Show Gist options
  • Save AKB428/15ad107cf6af4fbbfc46 to your computer and use it in GitHub Desktop.
Save AKB428/15ad107cf6af4fbbfc46 to your computer and use it in GitHub Desktop.
ElixirでMySQLのdatetime型をUNIX TIMESTAMPに変換する ref: http://qiita.com/AKB428/items/1e6491b4badcf416d9be
defmodule UnixTime do
def convert_date_to_unixtime(created_at) do
#JSTの場合9Hにしておく
epoch = {{1970, 1, 1}, {9, 0, 0}}
epoch_gs = :calendar.datetime_to_gregorian_seconds(epoch)
{{year, month, day}, {hour, minute, second, msec}} = created_at
gs = :calendar.datetime_to_gregorian_seconds({{year, month, day}, {hour, minute, second}})
gs - epoch_gs
end
end
UnixTime.convert_date_to_unixtime(updated_at)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment