0
@time = Time.now
 if @time.zone == "IST"
  @time = Time.now.utc  
 end

i tried the above code, and it works for me. but how to change the time according to the country when the application is opened in some other country.

i.e., If the application is opened in PDT it should show time in PDT format when the same application is opened in UTC it should show time in UTC format by checking the zone automatically. How to apply this for all the timezone in ruby?

i have tried checking for one timezone, how to do it for all the timezone!!

Is there any gem?

Thanks..

1 Answers1

0

This will do the same thing as config.time_zone but on a per request basis. I still recommend to change the default config.time_zone to a time zone that is a good default for your users.

around_action :user_time_zone, if: :current_user

def user_time_zone(&block)
  Time.use_zone(current_user.time_zone, &block)
end
M Zippka
  • 93
  • 13