Here interests a trace. question:

As in PostgreSQL, to make the time point to the current time zone (otherwise I’m kind of in the +3 hour zone) but when I create a post ..

My created_at (column) indicates a time of +0 hours.

I create a post at 11 pm, and points to 9 pm.

How can this be fixed?

    3 answers 3

    Keep all the same as. Either save with server timezone, either with GMT + 0, or with GMT + 0 and not write a zone to the database at all (the main thing is not to save with a user timezone, because it is different for all users, and you will have to drag the author of the post to the request). Display the same dates as follows:

    Time.zone.at (post.created_at) 

    It is also a good idea to take into account that if a user enters manually somewhere, then you need to convert it back from user timezone to server time.

      PostgreSQL has two different types for storing a point in time - "timestamp with time zone" and "timestamp without time zone". By default (i.e., when it is just written "timestamp"), the second one is used - without a time zone. Apparently, this is the problem.

      • and what exactly in the migration to write? I have -> "t.timestamps" (which will add cteated_at and updated_at. - Dmytro Vasin
      • This should be asked from connoisseurs "rails". I dont know. - Shamov

      Coped with the question through

        before_filter :set_timezone def set_timezone min = request.cookies['time_zone'].to_i Time.zone = ActiveSupport::TimeZone[min] end application.js application_controller function SetTimeZone() { var today = new Date(); var offset = -(today.getTimezoneOffset()/60); $.cookie('time_zone', offset); } SetTimeZone();