Created
November 3, 2015 18:36
-
-
Save AKB428/15ad107cf6af4fbbfc46 to your computer and use it in GitHub Desktop.
ElixirでMySQLのdatetime型をUNIX TIMESTAMPに変換する ref: http://qiita.com/AKB428/items/1e6491b4badcf416d9be
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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