Rails stores all DateTime
s in the UTC timezone. I need to display that time now to the user in the timezone that their browser reports they're in. Is there an easy way to do this?
Using latest Rails (3.2.13).
Rails stores all DateTime
s in the UTC timezone. I need to display that time now to the user in the timezone that their browser reports they're in. Is there an easy way to do this?
Using latest Rails (3.2.13).
in client (js):
function set_time_zone_offset() {
var current_time = new Date();
$.cookie('time_zone', current_time.getTimezoneOffset());
}
in Application Controller:
before_filter :set_timezone
def set_timezone
min = request.cookies["time_zone"].to_i
Time.zone = ActiveSupport::TimeZone[-min.minutes]
end