How can I make timestamp() store datetime in a local time?

How can I make timestamp() store datetime in a local time?

I’ve been renewing a sort of community site written in PHP to Phoenix. As the service is used only in Japanese, and the existing records in DB(MySQL) have datetime column in JST( UTC + 9hour = JST, by the way). Also the timezone in the node is JST(/etc/localtime is /usr/share/zoneinfo/Asia/Tokyo).

Though the node works on the local timezone(JST), timestamp() in Ecto still stores the column, inserted_at and updated_at, in UTC.

I don’t have to consider the other timezone except for JST, so I want to fix all datetime(DB, application and return value sent to users) in JST, not in UTC.

Elixir core does only know about UTC as timezone, so you’d need to use a third party tool to create the JST datetime (or maybe :calender.local_time/0?) and set it manually. Also utc_datetime does as the name suggests store only UTC timestamps, so you either need to use naive_datetime as type (default) and skip timezone checks or implement your own Ecto.Type, which ensures datetimes are in JST.

Thank you. I’ll try it as you suggested!