Get Time in Any Time Zone
You can get the current time of any Time zone in your rails Application.
Rails provides methods for Time Conversions.
Here is a snippet to convert the Time zone to Pacific Time (USA)
Time.now.utc.in_time_zone('Pacific Time (US & Canada)')
This returns the Time according to the Pacific US Timing.
You can also make your application use the specific time zone by setting this in your environment.rb file
config.time_zone = 'UTC'
or
config.time_zone = 'Pacific Time (US & Canada)'
And one more thing, to get all the available Time Zones Try this in your rails console
include ActiveSupport
TimeZone.all
This will list all the available Time zones. Set anyone in your rails application according to your needs and voila you are done!!!
That's it.
Happy Hacking...
Written by Rajeev N Bharshetty
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#