Needs to create a Rails App where I want to get the time in local time Zone i.e. if the location is Delhi the time zone should be IST and if the the location is San Fransisco the time zone should be PDT.
How to accomplish this in ruby on rails?
P.S. One line code that can set the time zone automatically according to the location.
If you need the Olson time zone (because three-letter time zones are ambiguous, as are GMT offsets), it looks like there's no way to do it in pure Ruby/Rails. Ruby will only provide the short code (basically via
date +%Z
), and Rails uses the time zone of its configuration (default: UTC).That said, shelling out can be made to work in combination with another answer:
try this
Time.now.getlocal.zone